theoradec: move the QoS logic to libgstvideo

https://bugzilla.gnome.org/show_bug.cgi?id=658241
This commit is contained in:
Vincent Penquerc'h 2011-09-07 16:04:14 +01:00
parent eb03323fb6
commit 149a4ce390
2 changed files with 13 additions and 71 deletions

View file

@ -231,15 +231,9 @@ gst_theora_dec_reset (GstTheoraDec * dec)
dec->discont = TRUE; dec->discont = TRUE;
dec->frame_nr = -1; dec->frame_nr = -1;
dec->seqnum = gst_util_seqnum_next (); dec->seqnum = gst_util_seqnum_next ();
dec->dropped = 0; gst_video_qos_tracker_reset (&dec->qt);
dec->processed = 0;
gst_segment_init (&dec->segment, GST_FORMAT_TIME); gst_segment_init (&dec->segment, GST_FORMAT_TIME);
GST_OBJECT_LOCK (dec);
dec->proportion = 1.0;
dec->earliest_time = -1;
GST_OBJECT_UNLOCK (dec);
g_list_foreach (dec->queued, (GFunc) gst_mini_object_unref, NULL); g_list_foreach (dec->queued, (GFunc) gst_mini_object_unref, NULL);
g_list_free (dec->queued); g_list_free (dec->queued);
dec->queued = NULL; dec->queued = NULL;
@ -576,23 +570,12 @@ theora_dec_src_event (GstPad * pad, GstEvent * event)
} }
case GST_EVENT_QOS: case GST_EVENT_QOS:
{ {
gdouble proportion;
GstClockTimeDiff diff;
GstClockTime timestamp;
gst_event_parse_qos (event, &proportion, &diff, &timestamp);
/* we cannot randomly skip frame decoding since we don't have /* we cannot randomly skip frame decoding since we don't have
* B frames. we can however use the timestamp and diff to not * B frames. we can however use the timestamp and diff to not
* push late frames. This would at least save us the time to * push late frames. This would at least save us the time to
* crop/memcpy the data. */ * crop/memcpy the data. */
GST_OBJECT_LOCK (dec); gst_video_qos_tracker_update (&dec->qt, event,
dec->proportion = proportion; GST_CLOCK_TIME_NONE, GST_VIDEO_QOS_TRACKER_DIFF);
dec->earliest_time = timestamp + diff;
GST_OBJECT_UNLOCK (dec);
GST_DEBUG_OBJECT (dec, "got QoS %" GST_TIME_FORMAT ", %" G_GINT64_FORMAT,
GST_TIME_ARGS (timestamp), diff);
res = gst_pad_push_event (dec->sinkpad, event); res = gst_pad_push_event (dec->sinkpad, event);
break; break;
@ -1146,50 +1129,11 @@ theora_handle_data_packet (GstTheoraDec * dec, ogg_packet * packet,
if (G_UNLIKELY (th_decode_packetin (dec->decoder, packet, &gp) < 0)) if (G_UNLIKELY (th_decode_packetin (dec->decoder, packet, &gp) < 0))
goto decode_error; goto decode_error;
if (outtime != -1) {
gboolean need_skip;
GstClockTime running_time;
GstClockTime earliest_time;
gdouble proportion;
/* qos needs to be done on running time */
running_time = gst_segment_to_running_time (&dec->segment, GST_FORMAT_TIME,
outtime);
GST_OBJECT_LOCK (dec);
proportion = dec->proportion;
earliest_time = dec->earliest_time;
/* check for QoS, don't perform the last steps of getting and /* check for QoS, don't perform the last steps of getting and
* pushing the buffers that are known to be late. */ * pushing the buffers that are known to be late. */
need_skip = earliest_time != -1 && running_time <= earliest_time; if (gst_video_qos_tracker_process_frame (&dec->qt, &dec->segment, outtime,
GST_OBJECT_UNLOCK (dec); outdur))
if (need_skip) {
GstMessage *qos_msg;
guint64 stream_time;
gint64 jitter;
GST_DEBUG_OBJECT (dec, "skipping decoding: qostime %"
GST_TIME_FORMAT " <= %" GST_TIME_FORMAT,
GST_TIME_ARGS (running_time), GST_TIME_ARGS (earliest_time));
dec->dropped++;
stream_time =
gst_segment_to_stream_time (&dec->segment, GST_FORMAT_TIME, outtime);
jitter = GST_CLOCK_DIFF (running_time, earliest_time);
qos_msg =
gst_message_new_qos (GST_OBJECT_CAST (dec), FALSE, running_time,
stream_time, outtime, outdur);
gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
dec->processed, dec->dropped);
gst_element_post_message (GST_ELEMENT_CAST (dec), qos_msg);
goto dropping_qos; goto dropping_qos;
}
}
/* this does postprocessing and set up the decoded frame /* this does postprocessing and set up the decoded frame
* pointers in our yuv variable */ * pointers in our yuv variable */
@ -1212,8 +1156,6 @@ theora_handle_data_packet (GstTheoraDec * dec, ogg_packet * packet,
GST_BUFFER_TIMESTAMP (out) = outtime; GST_BUFFER_TIMESTAMP (out) = outtime;
GST_BUFFER_DURATION (out) = outdur; GST_BUFFER_DURATION (out) = outdur;
dec->processed++;
if (dec->segment.rate >= 0.0) if (dec->segment.rate >= 0.0)
result = theora_dec_push_forward (dec, out); result = theora_dec_push_forward (dec, out);
else else
@ -1506,6 +1448,7 @@ theora_dec_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY: case GST_STATE_CHANGE_NULL_TO_READY:
gst_video_qos_tracker_init (&dec->qt, element);
break; break;
case GST_STATE_CHANGE_READY_TO_PAUSED: case GST_STATE_CHANGE_READY_TO_PAUSED:
th_info_clear (&dec->info); th_info_clear (&dec->info);
@ -1536,6 +1479,7 @@ theora_dec_change_state (GstElement * element, GstStateChange transition)
gst_theora_dec_reset (dec); gst_theora_dec_reset (dec);
break; break;
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
gst_video_qos_tracker_clear (&dec->qt);
break; break;
default: default:
break; break;

View file

@ -25,6 +25,7 @@
#endif #endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h>
#include <theora/theoradec.h> #include <theora/theoradec.h>
#include <string.h> #include <string.h>
@ -97,11 +98,8 @@ struct _GstTheoraDec
gboolean discont; gboolean discont;
guint32 seqnum; guint32 seqnum;
/* QoS stuff */ /* with LOCK*/ /* QoS stuff */
gdouble proportion; GstVideoQoSTracker qt;
GstClockTime earliest_time;
guint64 processed;
guint64 dropped;
gboolean have_par; gboolean have_par;
gint par_num; gint par_num;