video-src: use FLAG_MAP_BUFFERS

This commit is contained in:
Wim Taymans 2018-11-08 11:43:35 +01:00
parent 3267667d94
commit 7925aed863

View file

@ -58,33 +58,19 @@ static void on_timeout(void *userdata, uint64_t expirations)
struct pw_buffer *b; struct pw_buffer *b;
struct spa_buffer *buf; struct spa_buffer *buf;
int i, j; int i, j;
uint8_t *p, *map; uint8_t *p;
struct spa_meta_header *h; struct spa_meta_header *h;
struct spa_meta *m; struct spa_meta *m;
pw_log_trace("timeout"); pw_log_trace("timeout");
b = pw_stream_dequeue_buffer(data->stream); if ((b = pw_stream_dequeue_buffer(data->stream)) == NULL) {
if (b == NULL) {
pw_log_warn("out of buffers"); pw_log_warn("out of buffers");
return; return;
} }
buf = b->buffer;
if (buf->datas[0].type == SPA_DATA_MemFd || buf = b->buffer;
buf->datas[0].type == SPA_DATA_DmaBuf) { if ((p = buf->datas[0].data) == NULL)
map =
mmap(NULL, buf->datas[0].maxsize + buf->datas[0].mapoffset,
PROT_READ | PROT_WRITE, MAP_SHARED, buf->datas[0].fd, 0);
if (map == MAP_FAILED) {
printf("failed to mmap: %s\n", strerror(errno));
return;
}
p = SPA_MEMBER(map, buf->datas[0].mapoffset, uint8_t);
} else if (buf->datas[0].type == SPA_DATA_MemPtr) {
map = NULL;
p = buf->datas[0].data;
} else
return; return;
if ((h = spa_buffer_find_meta_data(buf, SPA_META_Header, sizeof(*h)))) { if ((h = spa_buffer_find_meta_data(buf, SPA_META_Header, sizeof(*h)))) {
@ -119,9 +105,6 @@ static void on_timeout(void *userdata, uint64_t expirations)
data->counter += 13; data->counter += 13;
} }
if (map)
munmap(map, buf->datas[0].maxsize + buf->datas[0].mapoffset);
buf->datas[0].chunk->size = buf->datas[0].maxsize; buf->datas[0].chunk->size = buf->datas[0].maxsize;
pw_stream_queue_buffer(data->stream, b); pw_stream_queue_buffer(data->stream, b);
@ -262,7 +245,9 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo
pw_stream_connect(data->stream, pw_stream_connect(data->stream,
PW_DIRECTION_OUTPUT, PW_DIRECTION_OUTPUT,
SPA_ID_INVALID, PW_STREAM_FLAG_DRIVER, SPA_ID_INVALID,
PW_STREAM_FLAG_DRIVER |
PW_STREAM_FLAG_MAP_BUFFERS,
params, 1); params, 1);
break; break;
} }