Commit 6379ca86 authored by Erwan Croze's avatar Erwan Croze 👋🏻

Fix compliance with RFC 7741 VP8 start partition

parent 6f9a8669
......@@ -198,7 +198,7 @@ static void enc_preprocess(MSFilter *f) {
if (s->cfg.g_threads <= 2) cpuused = 8;
else if (s->cfg.g_threads <= 4) cpuused = 5;
else cpuused = 1;
}
if( s->cfg.g_threads == 1 ){
/* on mono-core iOS devices, we reduce the quality a bit more due to VP8 being slower with new Clang compilers */
......@@ -232,11 +232,11 @@ static void enc_preprocess(MSFilter *f) {
} else if (s->frame_count == 0) {
ms_video_starter_init(&s->starter);
}
s->process_thread = ms_worker_thread_new();
qinit(&s->entry_q);
s->exit_q = ms_queue_new(0, 0, 0, 0);
s->ready = TRUE;
}
......@@ -455,9 +455,9 @@ static void enc_process_frame_task(void *obj) {
MSPicture yuv;
bool_t is_ref_frame=FALSE;
vpx_image_t img;
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
ms_filter_lock(f);
if ((im = getq(&s->entry_q)) == NULL) {
ms_warning("VP8 async process: No frame in entry queue");
......@@ -470,7 +470,7 @@ static void enc_process_frame_task(void *obj) {
return;
}
#endif
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
if (s->entry_q.q_mcount >= 3){
/*don't let too much buffers to be queued here, it makes no sense for a real time processing and would consume too much memory*/
......@@ -510,6 +510,7 @@ static void enc_process_frame_task(void *obj) {
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt;
bctbx_list_t *list = NULL;
int current_partition_id = -1;
/* Update the frames state. */
is_ref_frame=FALSE;
......@@ -536,7 +537,7 @@ static void enc_process_frame_task(void *obj) {
}
/* Pack the encoded frame. */
while( (pkt = vpx_codec_get_cx_data(&s->codec, &iter)) ) {
while ((pkt = vpx_codec_get_cx_data(&s->codec, &iter))) {
if ((pkt->kind == VPX_CODEC_CX_FRAME_PKT) && (pkt->data.frame.sz > 0)) {
Vp8RtpFmtPacket *packet = ms_new0(Vp8RtpFmtPacket, 1);
......@@ -545,7 +546,6 @@ static void enc_process_frame_task(void *obj) {
packet->m->b_wptr += pkt->data.frame.sz;
mblk_set_timestamp_info(packet->m, timestamp);
packet->pd = ms_new0(Vp8RtpFmtPayloadDescriptor, 1);
packet->pd->start_of_partition = TRUE;
packet->pd->non_reference_frame = s->avpf_enabled && !is_ref_frame;
if (s->avpf_enabled == TRUE) {
packet->pd->extended_control_bits_present = TRUE;
......@@ -556,12 +556,20 @@ static void enc_process_frame_task(void *obj) {
packet->pd->pictureid_present = FALSE;
}
if (s->flags & VPX_CODEC_USE_OUTPUT_PARTITION) {
if (pkt->data.frame.partition_id != current_partition_id) {
current_partition_id = pkt->data.frame.partition_id;
packet->pd->start_of_partition = TRUE;
}
packet->pd->pid = (uint8_t)pkt->data.frame.partition_id;
if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
mblk_set_marker_info(packet->m, TRUE);
}
} else {
packet->pd->pid = 0;
if (current_partition_id != 0) {
packet->pd->start_of_partition = TRUE;
current_partition_id = 0;
}
mblk_set_marker_info(packet->m, TRUE);
}
list = bctbx_list_append(list, packet);
......@@ -575,7 +583,7 @@ static void enc_process_frame_task(void *obj) {
(flags & VP8_EFLAG_NO_REF_ARF) ? "NOREFARF" : " ",
(flags & VP8_EFLAG_NO_REF_LAST) ? "NOREFLAST" : " ");
#endif
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
ms_filter_lock(f);
vp8rtpfmt_packer_process(&s->packer, list, s->exit_q, f->factory);
......@@ -631,7 +639,7 @@ static void enc_process(MSFilter *f) {
enc_process_frame_task((void*)f);
#endif
}
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
/* Put each frame we have in exit_q in f->output[0] */
while ((exit_f = ms_queue_get(s->exit_q)) != NULL) {
......@@ -747,7 +755,7 @@ static int enc_notify_sli(MSFilter *f, void *data) {
diff=(64 + (int)(most_recent & 0x3F) - (int)(sli->picture_id & 0x3F)) % 64;
s->last_sli_id=most_recent-diff;
fs=enc_get_most_recent_reference_frame(s,FALSE);
ms_message("VP8: receiving SLI with pic id [%i], last-ref=[%i], most recent pic id=[%i]",s->last_sli_id, fs ? (int)fs->picture_id : 0, most_recent);
if (s->frames_state.golden.picture_id == s->last_sli_id) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment