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

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

Issue 883403002: Parsing of encoded duration for unencrypted opus streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing review feedback Created 5 years, 10 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/media_export.h" 15 #include "media/base/media_export.h"
15 #include "media/base/media_log.h" 16 #include "media/base/media_log.h"
16 #include "media/base/stream_parser.h" 17 #include "media/base/stream_parser.h"
17 #include "media/base/stream_parser_buffer.h" 18 #include "media/base/stream_parser_buffer.h"
18 #include "media/formats/webm/webm_parser.h" 19 #include "media/formats/webm/webm_parser.h"
19 #include "media/formats/webm/webm_tracks_parser.h" 20 #include "media/formats/webm/webm_tracks_parser.h"
20 21
21 namespace media { 22 namespace media {
22 23
23 class MEDIA_EXPORT WebMClusterParser : public WebMParserClient { 24 class MEDIA_EXPORT WebMClusterParser : public WebMParserClient {
24 public: 25 public:
wolenetz 2015/02/03 22:47:02 fyi: I just noticed this class has multiple public
chcunningham 2015/02/05 02:48:22 I don't think its needed. Happy to clean up in lat
wolenetz 2015/02/05 23:04:59 Acknowledged.
25 typedef StreamParser::TrackId TrackId; 26 typedef StreamParser::TrackId TrackId;
26 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; 27 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue;
27 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap; 28 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap;
28 29
29 // 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
30 // 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.
31 // TODO(wolenetz/acolwell): Parse audio codebook to determine missing audio
32 // frame durations. See http://crbug.com/351166.
33 enum { 32 enum {
34 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz 33 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz
35 kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls 34 kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls
36 }; 35 };
37 36
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
39 // to the duration of each frame of the packet in microseconds. See
40 // http://goo.gl/2RmoxA
wolenetz 2015/02/03 22:47:02 I was wrong. Using full URL is more common. Also l
chcunningham 2015/02/05 02:48:22 Done.
41 static const uint16 kOpusFrameDurationsMu[];
wolenetz 2015/02/03 22:47:02 _t
chcunningham 2015/02/05 02:48:22 Done.
42
38 private: 43 private:
39 // Helper class that manages per-track state. 44 // Helper class that manages per-track state.
40 class Track { 45 class Track {
41 public: 46 public:
42 Track(int track_num, 47 Track(int track_num,
43 bool is_video, 48 bool is_video,
44 base::TimeDelta default_duration, 49 base::TimeDelta default_duration,
45 const LogCB& log_cb); 50 const LogCB& log_cb);
46 ~Track(); 51 ~Track();
47 52
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 public: 141 public:
137 WebMClusterParser(int64 timecode_scale, 142 WebMClusterParser(int64 timecode_scale,
138 int audio_track_num, 143 int audio_track_num,
139 base::TimeDelta audio_default_duration, 144 base::TimeDelta audio_default_duration,
140 int video_track_num, 145 int video_track_num,
141 base::TimeDelta video_default_duration, 146 base::TimeDelta video_default_duration,
142 const WebMTracksParser::TextTracks& text_tracks, 147 const WebMTracksParser::TextTracks& text_tracks,
143 const std::set<int64>& ignored_tracks, 148 const std::set<int64>& ignored_tracks,
144 const std::string& audio_encryption_key_id, 149 const std::string& audio_encryption_key_id,
145 const std::string& video_encryption_key_id, 150 const std::string& video_encryption_key_id,
151 const AudioCodec audio_codec_,
146 const LogCB& log_cb); 152 const LogCB& log_cb);
147 ~WebMClusterParser() override; 153 ~WebMClusterParser() override;
148 154
149 // Resets the parser state so it can accept a new cluster. 155 // Resets the parser state so it can accept a new cluster.
150 void Reset(); 156 void Reset();
151 157
152 // Parses a WebM cluster element in |buf|. 158 // Parses a WebM cluster element in |buf|.
153 // 159 //
154 // Returns -1 if the parse fails. 160 // Returns -1 if the parse fails.
155 // Returns 0 if more data is needed. 161 // Returns 0 if more data is needed.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // bound.) 226 // bound.)
221 // Parse() or Reset() must be called between calls to UpdateReadyBuffers() to 227 // Parse() or Reset() must be called between calls to UpdateReadyBuffers() to
222 // clear each track's ready buffers and to reset |ready_buffer_upper_bound_| 228 // clear each track's ready buffers and to reset |ready_buffer_upper_bound_|
223 // to kNoDecodeTimestamp(). 229 // to kNoDecodeTimestamp().
224 void UpdateReadyBuffers(); 230 void UpdateReadyBuffers();
225 231
226 // Search for the indicated track_num among the text tracks. Returns NULL 232 // Search for the indicated track_num among the text tracks. Returns NULL
227 // if that track num is not a text track. 233 // if that track num is not a text track.
228 Track* FindTextTrack(int track_num); 234 Track* FindTextTrack(int track_num);
229 235
236 // Attempts to read the duration from the encoded audio data. This obviously
237 // violates layering rules, but is useful for MSE to know duration in cases
238 // where it isn't explicitly given and cannot be calculated for Blocks at the
239 // end of a Cluster (the next Cluster in playback-order may not be the next
240 // Cluster we parse, so we can't simply use the delta of the first Block in
241 // the next Cluster). Avoid calling if encrypted; may produce unexpected
242 // output. See implementation for supported codecs.
wolenetz 2015/02/03 22:47:02 nit: though private, would be nice to have retval
chcunningham 2015/02/05 02:48:22 Done.
243 base::TimeDelta TryGetEncodedAudioDuration(const uint8* data, int size);
wolenetz 2015/02/03 22:47:02 nit: const method?
chcunningham 2015/02/05 02:48:22 We chatted. The MEDIA_LOGS break const-ness :(
wolenetz 2015/02/05 23:04:59 Acknowledged.
244
245 // Reads Opus packet header to determine packet duration.
wolenetz 2015/02/03 22:47:02 nit: ditto retval documentation
chcunningham 2015/02/05 02:48:22 Done.
246 base::TimeDelta ReadOpusDuration(const uint8* data, int size);
wolenetz 2015/02/03 22:47:02 nit: const method?
chcunningham 2015/02/05 02:48:22 Same issue with MEDIA_LOG
wolenetz 2015/02/05 23:04:59 Acknowledged.
247
230 double timecode_multiplier_; // Multiplier used to convert timecodes into 248 double timecode_multiplier_; // Multiplier used to convert timecodes into
231 // microseconds. 249 // microseconds.
232 std::set<int64> ignored_tracks_; 250 std::set<int64> ignored_tracks_;
233 std::string audio_encryption_key_id_; 251 std::string audio_encryption_key_id_;
234 std::string video_encryption_key_id_; 252 std::string video_encryption_key_id_;
253 const AudioCodec audio_codec_;
235 254
236 WebMListParser parser_; 255 WebMListParser parser_;
237 256
238 int64 last_block_timecode_; 257 int64 last_block_timecode_;
239 scoped_ptr<uint8[]> block_data_; 258 scoped_ptr<uint8[]> block_data_;
240 int block_data_size_; 259 int block_data_size_;
241 int64 block_duration_; 260 int64 block_duration_;
242 int64 block_add_id_; 261 int64 block_add_id_;
243 262
244 scoped_ptr<uint8[]> block_additional_data_; 263 scoped_ptr<uint8[]> block_additional_data_;
(...skipping 26 matching lines...) Expand all
271 DecodeTimestamp ready_buffer_upper_bound_; 290 DecodeTimestamp ready_buffer_upper_bound_;
272 291
273 LogCB log_cb_; 292 LogCB log_cb_;
274 293
275 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); 294 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser);
276 }; 295 };
277 296
278 } // namespace media 297 } // namespace media
279 298
280 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 299 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698