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

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: Fixing try failure, remove unused variable for some builds. Created 5 years, 8 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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "media/base/audio_decoder_config.h" 14 #include "media/base/audio_decoder_config.h"
15 #include "media/base/media_export.h" 15 #include "media/base/media_export.h"
16 #include "media/base/media_log.h" 16 #include "media/base/media_log.h"
17 #include "media/base/stream_parser.h" 17 #include "media/base/stream_parser.h"
18 #include "media/base/stream_parser_buffer.h" 18 #include "media/base/stream_parser_buffer.h"
19 #include "media/formats/webm/webm_parser.h" 19 #include "media/formats/webm/webm_parser.h"
20 #include "media/formats/webm/webm_tracks_parser.h" 20 #include "media/formats/webm/webm_tracks_parser.h"
21 21
22 namespace media { 22 namespace media {
23 23
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 // Numbers chosen to estimate the duration of a buffer if none is set and
31 // set and there is not enough information to get a better estimate. 31 // there is not enough information to get a better estimate.
32 enum { 32 enum {
33 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz 33 // Common 1k samples @44.1kHz
34 kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls 34 kDefaultAudioBufferDurationInMs = 23,
35
36 // Chosen to represent 16fps duration, which will prevent MSE stalls in
37 // videos with frame-rates as low as 8fps.
38 kDefaultVideoBufferDurationInMs = 63
35 }; 39 };
36 40
37 // Opus packets encode the duration and other parameters in the 5 most 41 // 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 42 // 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 43 // to the duration of each frame of the packet in microseconds. See
40 // https://tools.ietf.org/html/rfc6716#page-14 44 // https://tools.ietf.org/html/rfc6716#page-14
41 static const uint16_t kOpusFrameDurationsMu[]; 45 static const uint16_t kOpusFrameDurationsMu[];
42 46
43 private: 47 private:
44 // Helper class that manages per-track state. 48 // Helper class that manages per-track state.
(...skipping 20 matching lines...) Expand all
65 const BufferQueue& ready_buffers() const { return ready_buffers_; } 69 const BufferQueue& ready_buffers() const { return ready_buffers_; }
66 70
67 // If |last_added_buffer_missing_duration_| is set, updates its duration 71 // If |last_added_buffer_missing_duration_| is set, updates its duration
68 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets 72 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets
69 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing 73 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing
70 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or 74 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or
71 // otherwise adds |buffer| to |buffers_|. 75 // otherwise adds |buffer| to |buffers_|.
72 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer); 76 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer);
73 77
74 // If |last_added_buffer_missing_duration_| is set, updates its duration to 78 // If |last_added_buffer_missing_duration_| is set, updates its duration to
75 // be non-kNoTimestamp() value of |estimated_next_frame_duration_| or an 79 // be non-kNoTimestamp() value of |estimated_next_frame_duration_| or a
76 // arbitrary default, then adds it to |buffers_| and unsets 80 // hard-coded default, then adds it to |buffers_| and unsets
77 // |last_added_buffer_missing_duration_|. (This method helps stream parser 81 // |last_added_buffer_missing_duration_|. (This method helps stream parser
78 // emit all buffers in a media segment before signaling end of segment.) 82 // emit all buffers in a media segment before signaling end of segment.)
79 void ApplyDurationEstimateIfNeeded(); 83 void ApplyDurationEstimateIfNeeded();
80 84
81 // Clears |ready_buffers_| (use ExtractReadyBuffers() to fill it again). 85 // Clears |ready_buffers_| (use ExtractReadyBuffers() to fill it again).
82 // Leaves as-is |buffers_| and any possibly held-aside buffer that is 86 // Leaves as-is |buffers_| and any possibly held-aside buffer that is
83 // missing duration. 87 // missing duration.
84 void ClearReadyBuffers(); 88 void ClearReadyBuffers();
85 89
86 // Clears all buffer state, including any possibly held-aside buffer that 90 // 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 104 // Helper that sanity-checks |buffer| duration, updates
101 // |estimated_next_frame_duration_|, and adds |buffer| to |buffers_|. 105 // |estimated_next_frame_duration_|, and adds |buffer| to |buffers_|.
102 // Returns false if |buffer| failed sanity check and therefore was not added 106 // Returns false if |buffer| failed sanity check and therefore was not added
103 // to |buffers_|. Returns true otherwise. 107 // to |buffers_|. Returns true otherwise.
104 bool QueueBuffer(const scoped_refptr<StreamParserBuffer>& buffer); 108 bool QueueBuffer(const scoped_refptr<StreamParserBuffer>& buffer);
105 109
106 // Helper that calculates the buffer duration to use in 110 // Helper that calculates the buffer duration to use in
107 // ApplyDurationEstimateIfNeeded(). 111 // ApplyDurationEstimateIfNeeded().
108 base::TimeDelta GetDurationEstimate(); 112 base::TimeDelta GetDurationEstimate();
109 113
114 // Counts the number of estimated durations used in this track. Used to
115 // prevent log spam for MEDIA_LOG()s about estimated duration.
116 int num_duration_estimates_;
117
110 int track_num_; 118 int track_num_;
111 bool is_video_; 119 bool is_video_;
112 120
113 // Parsed track buffers, each with duration and in (decode) timestamp order, 121 // 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 122 // that have not yet been extracted into |ready_buffers_|. Note that up to
115 // one additional buffer missing duration may be tracked by 123 // one additional buffer missing duration may be tracked by
116 // |last_added_buffer_missing_duration_|. 124 // |last_added_buffer_missing_duration_|.
117 BufferQueue buffers_; 125 BufferQueue buffers_;
118 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_; 126 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_;
119 127
120 // Buffers in (decode) timestamp order that were previously parsed into and 128 // Buffers in (decode) timestamp order that were previously parsed into and
121 // extracted from |buffers_|. Buffers are moved from |buffers_| to 129 // extracted from |buffers_|. Buffers are moved from |buffers_| to
122 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified 130 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified
123 // upper bound timestamp. Track users can therefore extract only those 131 // upper bound timestamp. Track users can therefore extract only those
124 // parsed buffers which are "ready" for emission (all before some maximum 132 // parsed buffers which are "ready" for emission (all before some maximum
125 // timestamp). 133 // timestamp).
126 BufferQueue ready_buffers_; 134 BufferQueue ready_buffers_;
127 135
128 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. 136 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used.
129 base::TimeDelta default_duration_; 137 base::TimeDelta default_duration_;
130 138
131 // If kNoTimestamp(), then a default value will be used. This estimate is 139 // 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 140 // the maximum (for video), or minimum (for audio) duration seen so far for
133 // only if |default_duration_| is kNoTimestamp(). 141 // this track, and is used only if |default_duration_| is kNoTimestamp().
142 // TODO(chcunningham): Use maximum for audio too, adding checks to disable
143 // splicing when these estimates are observed in SourceBufferStream.
134 base::TimeDelta estimated_next_frame_duration_; 144 base::TimeDelta estimated_next_frame_duration_;
135 145
136 LogCB log_cb_; 146 LogCB log_cb_;
137 }; 147 };
138 148
139 typedef std::map<int, Track> TextTrackMap; 149 typedef std::map<int, Track> TextTrackMap;
140 150
141 public: 151 public:
142 WebMClusterParser(int64 timecode_scale, 152 WebMClusterParser(int64 timecode_scale,
143 int audio_track_num, 153 int audio_track_num,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 DecodeTimestamp ready_buffer_upper_bound_; 316 DecodeTimestamp ready_buffer_upper_bound_;
307 317
308 LogCB log_cb_; 318 LogCB log_cb_;
309 319
310 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); 320 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser);
311 }; 321 };
312 322
313 } // namespace media 323 } // namespace media
314 324
315 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 325 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
OLDNEW
« no previous file with comments | « media/filters/source_buffer_stream_unittest.cc ('k') | media/formats/webm/webm_cluster_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698