Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: media/formats/webm/webm_cluster_parser.h

Issue 1018373003: Improving WebM video duration estimation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding limited media log (10 times max) for WebM duration estimates. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 5 #ifndef MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 13 matching lines...) Expand all
24 class MEDIA_EXPORT WebMClusterParser : public WebMParserClient { 24 class MEDIA_EXPORT WebMClusterParser : public WebMParserClient {
25 public: 25 public:
26 typedef StreamParser::TrackId TrackId; 26 typedef StreamParser::TrackId TrackId;
27 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; 27 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue;
28 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap; 28 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap;
29 29
30 // Arbitrarily-chosen numbers to estimate the duration of a buffer if none is 30 // Arbitrarily-chosen numbers to estimate the duration of a buffer if none is
31 // set and there is not enough information to get a better estimate. 31 // set and there is not enough information to get a better estimate.
32 enum { 32 enum {
33 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz 33 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz
34 kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls 34 kDefaultVideoBufferDurationInMs = 63 // Low 16fps to reduce stalls
wolenetz 2015/03/28 00:26:06 nit: comment here (and elaborate in CL description
chcunningham 2015/04/13 23:25:18 Done.
35 }; 35 };
36 36
37 // Opus packets encode the duration and other parameters in the 5 most 37 // Opus packets encode the duration and other parameters in the 5 most
38 // significant bits of the first byte. The index in this array corresponds 38 // significant bits of the first byte. The index in this array corresponds
39 // to the duration of each frame of the packet in microseconds. See 39 // to the duration of each frame of the packet in microseconds. See
40 // https://tools.ietf.org/html/rfc6716#page-14 40 // https://tools.ietf.org/html/rfc6716#page-14
41 static const uint16_t kOpusFrameDurationsMu[]; 41 static const uint16_t kOpusFrameDurationsMu[];
42 42
43 private: 43 private:
44 // Helper class that manages per-track state. 44 // Helper class that manages per-track state.
(...skipping 20 matching lines...) Expand all
65 const BufferQueue& ready_buffers() const { return ready_buffers_; } 65 const BufferQueue& ready_buffers() const { return ready_buffers_; }
66 66
67 // If |last_added_buffer_missing_duration_| is set, updates its duration 67 // If |last_added_buffer_missing_duration_| is set, updates its duration
68 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets 68 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets
69 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing 69 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing
70 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or 70 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or
71 // otherwise adds |buffer| to |buffers_|. 71 // otherwise adds |buffer| to |buffers_|.
72 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer); 72 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer);
73 73
74 // If |last_added_buffer_missing_duration_| is set, updates its duration to 74 // If |last_added_buffer_missing_duration_| is set, updates its duration to
75 // be non-kNoTimestamp() value of |estimated_next_frame_duration_| or an 75 // be non-kNoTimestamp() value of |estimated_next_frame_duration_| or a
76 // arbitrary default, then adds it to |buffers_| and unsets 76 // hard-coded default, then adds it to |buffers_| and unsets
77 // |last_added_buffer_missing_duration_|. (This method helps stream parser 77 // |last_added_buffer_missing_duration_|. (This method helps stream parser
78 // emit all buffers in a media segment before signaling end of segment.) 78 // emit all buffers in a media segment before signaling end of segment.)
79 void ApplyDurationEstimateIfNeeded(); 79 void ApplyDurationEstimateIfNeeded();
80 80
81 // Clears |ready_buffers_| (use ExtractReadyBuffers() to fill it again). 81 // Clears |ready_buffers_| (use ExtractReadyBuffers() to fill it again).
82 // Leaves as-is |buffers_| and any possibly held-aside buffer that is 82 // Leaves as-is |buffers_| and any possibly held-aside buffer that is
83 // missing duration. 83 // missing duration.
84 void ClearReadyBuffers(); 84 void ClearReadyBuffers();
85 85
86 // Clears all buffer state, including any possibly held-aside buffer that 86 // Clears all buffer state, including any possibly held-aside buffer that
(...skipping 13 matching lines...) Expand all
100 // Helper that sanity-checks |buffer| duration, updates 100 // Helper that sanity-checks |buffer| duration, updates
101 // |estimated_next_frame_duration_|, and adds |buffer| to |buffers_|. 101 // |estimated_next_frame_duration_|, and adds |buffer| to |buffers_|.
102 // Returns false if |buffer| failed sanity check and therefore was not added 102 // Returns false if |buffer| failed sanity check and therefore was not added
103 // to |buffers_|. Returns true otherwise. 103 // to |buffers_|. Returns true otherwise.
104 bool QueueBuffer(const scoped_refptr<StreamParserBuffer>& buffer); 104 bool QueueBuffer(const scoped_refptr<StreamParserBuffer>& buffer);
105 105
106 // Helper that calculates the buffer duration to use in 106 // Helper that calculates the buffer duration to use in
107 // ApplyDurationEstimateIfNeeded(). 107 // ApplyDurationEstimateIfNeeded().
108 base::TimeDelta GetDurationEstimate(); 108 base::TimeDelta GetDurationEstimate();
109 109
110 // Counts the number of estimated durations used in this track. Used to
111 // prevent log spam for MEDIA_LOG()s about estimated duration.
112 int num_duration_estimates_;
113
110 int track_num_; 114 int track_num_;
111 bool is_video_; 115 bool is_video_;
112 116
113 // Parsed track buffers, each with duration and in (decode) timestamp order, 117 // Parsed track buffers, each with duration and in (decode) timestamp order,
114 // that have not yet been extracted into |ready_buffers_|. Note that up to 118 // that have not yet been extracted into |ready_buffers_|. Note that up to
115 // one additional buffer missing duration may be tracked by 119 // one additional buffer missing duration may be tracked by
116 // |last_added_buffer_missing_duration_|. 120 // |last_added_buffer_missing_duration_|.
117 BufferQueue buffers_; 121 BufferQueue buffers_;
118 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_; 122 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_;
119 123
120 // Buffers in (decode) timestamp order that were previously parsed into and 124 // Buffers in (decode) timestamp order that were previously parsed into and
121 // extracted from |buffers_|. Buffers are moved from |buffers_| to 125 // extracted from |buffers_|. Buffers are moved from |buffers_| to
122 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified 126 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified
123 // upper bound timestamp. Track users can therefore extract only those 127 // upper bound timestamp. Track users can therefore extract only those
124 // parsed buffers which are "ready" for emission (all before some maximum 128 // parsed buffers which are "ready" for emission (all before some maximum
125 // timestamp). 129 // timestamp).
126 BufferQueue ready_buffers_; 130 BufferQueue ready_buffers_;
127 131
128 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. 132 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used.
129 base::TimeDelta default_duration_; 133 base::TimeDelta default_duration_;
130 134
131 // If kNoTimestamp(), then a default value will be used. This estimate is 135 // If kNoTimestamp(), then a default value will be used. This estimate is
132 // the maximum duration seen or derived so far for this track, and is valid 136 // the maximum (for video), or minimum (for audio) duration seen so far for
133 // only if |default_duration_| is kNoTimestamp(). 137 // this track, and is used only if |default_duration_| is kNoTimestamp().
138 // TODO(chcunningham): Use maximum for audio too, adding checks to disable
139 // splicing when these estimates are observed in SourceBufferStream.
134 base::TimeDelta estimated_next_frame_duration_; 140 base::TimeDelta estimated_next_frame_duration_;
135 141
136 LogCB log_cb_; 142 LogCB log_cb_;
137 }; 143 };
138 144
139 typedef std::map<int, Track> TextTrackMap; 145 typedef std::map<int, Track> TextTrackMap;
140 146
141 public: 147 public:
142 WebMClusterParser(int64 timecode_scale, 148 WebMClusterParser(int64 timecode_scale,
143 int audio_track_num, 149 int audio_track_num,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 DecodeTimestamp ready_buffer_upper_bound_; 312 DecodeTimestamp ready_buffer_upper_bound_;
307 313
308 LogCB log_cb_; 314 LogCB log_cb_;
309 315
310 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); 316 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser);
311 }; 317 };
312 318
313 } // namespace media 319 } // namespace media
314 320
315 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 321 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698