|
|
|
@ -33,7 +33,7 @@ write_header(struct sc_v4l2_sink *vs, const AVPacket *packet) {
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
|
|
|
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
|
|
|
if (!extradata) {
|
|
|
|
if (!extradata) {
|
|
|
|
LOGC("Could not allocate extradata");
|
|
|
|
LOG_OOM();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -163,25 +163,21 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|
|
|
|
|
|
|
|
|
|
|
bool ok = sc_video_buffer_init(&vs->vb, vs->buffering_time, &cbs, vs);
|
|
|
|
bool ok = sc_video_buffer_init(&vs->vb, vs->buffering_time, &cbs, vs);
|
|
|
|
if (!ok) {
|
|
|
|
if (!ok) {
|
|
|
|
LOGE("Could not initialize video buffer");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ok = sc_video_buffer_start(&vs->vb);
|
|
|
|
ok = sc_video_buffer_start(&vs->vb);
|
|
|
|
if (!ok) {
|
|
|
|
if (!ok) {
|
|
|
|
LOGE("Could not start video buffer");
|
|
|
|
|
|
|
|
goto error_video_buffer_destroy;
|
|
|
|
goto error_video_buffer_destroy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ok = sc_mutex_init(&vs->mutex);
|
|
|
|
ok = sc_mutex_init(&vs->mutex);
|
|
|
|
if (!ok) {
|
|
|
|
if (!ok) {
|
|
|
|
LOGC("Could not create mutex");
|
|
|
|
|
|
|
|
goto error_video_buffer_stop_and_join;
|
|
|
|
goto error_video_buffer_stop_and_join;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ok = sc_cond_init(&vs->cond);
|
|
|
|
ok = sc_cond_init(&vs->cond);
|
|
|
|
if (!ok) {
|
|
|
|
if (!ok) {
|
|
|
|
LOGC("Could not create cond");
|
|
|
|
|
|
|
|
goto error_mutex_destroy;
|
|
|
|
goto error_mutex_destroy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -203,7 +199,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|
|
|
|
|
|
|
|
|
|
|
vs->format_ctx = avformat_alloc_context();
|
|
|
|
vs->format_ctx = avformat_alloc_context();
|
|
|
|
if (!vs->format_ctx) {
|
|
|
|
if (!vs->format_ctx) {
|
|
|
|
LOGE("Could not allocate v4l2 output context");
|
|
|
|
LOG_OOM();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -215,7 +211,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|
|
|
#ifdef SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL
|
|
|
|
#ifdef SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL
|
|
|
|
vs->format_ctx->url = strdup(vs->device_name);
|
|
|
|
vs->format_ctx->url = strdup(vs->device_name);
|
|
|
|
if (!vs->format_ctx->url) {
|
|
|
|
if (!vs->format_ctx->url) {
|
|
|
|
LOGE("Could not strdup v4l2 device name");
|
|
|
|
LOG_OOM();
|
|
|
|
goto error_avformat_free_context;
|
|
|
|
goto error_avformat_free_context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
@ -225,7 +221,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|
|
|
|
|
|
|
|
|
|
|
AVStream *ostream = avformat_new_stream(vs->format_ctx, encoder);
|
|
|
|
AVStream *ostream = avformat_new_stream(vs->format_ctx, encoder);
|
|
|
|
if (!ostream) {
|
|
|
|
if (!ostream) {
|
|
|
|
LOGE("Could not allocate new v4l2 stream");
|
|
|
|
LOG_OOM();
|
|
|
|
goto error_avformat_free_context;
|
|
|
|
goto error_avformat_free_context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -244,7 +240,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|
|
|
|
|
|
|
|
|
|
|
vs->encoder_ctx = avcodec_alloc_context3(encoder);
|
|
|
|
vs->encoder_ctx = avcodec_alloc_context3(encoder);
|
|
|
|
if (!vs->encoder_ctx) {
|
|
|
|
if (!vs->encoder_ctx) {
|
|
|
|
LOGC("Could not allocate codec context for v4l2");
|
|
|
|
LOG_OOM();
|
|
|
|
goto error_avio_close;
|
|
|
|
goto error_avio_close;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -261,13 +257,13 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
|
|
|
|
|
|
|
|
|
|
|
|
vs->frame = av_frame_alloc();
|
|
|
|
vs->frame = av_frame_alloc();
|
|
|
|
if (!vs->frame) {
|
|
|
|
if (!vs->frame) {
|
|
|
|
LOGE("Could not create v4l2 frame");
|
|
|
|
LOG_OOM();
|
|
|
|
goto error_avcodec_close;
|
|
|
|
goto error_avcodec_close;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vs->packet = av_packet_alloc();
|
|
|
|
vs->packet = av_packet_alloc();
|
|
|
|
if (!vs->packet) {
|
|
|
|
if (!vs->packet) {
|
|
|
|
LOGE("Could not allocate packet");
|
|
|
|
LOG_OOM();
|
|
|
|
goto error_av_frame_free;
|
|
|
|
goto error_av_frame_free;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|