Chromium Code Reviews| OLD | NEW |
|---|---|
| 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: |
| 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 // TODO(wolenetz/acolwell): Parse audio codebook to determine missing audio |
|
wolenetz
2015/01/30 01:48:08
nit: update bug comment :) (wolenetz/chcunningham)
chcunningham
2015/02/03 20:34:43
Done. I pulled the TODO out of this comment and pu
| |
| 32 // frame durations. See http://crbug.com/351166. | 33 // frame durations. See http://crbug.com/351166. |
| 33 enum { | 34 enum { |
| 34 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz | 35 kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz |
| 35 kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls | 36 kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls |
| 36 }; | 37 }; |
| 37 | 38 |
| 39 // Opus packets encode the duration and other parameters in the 5 most | |
|
wolenetz
2015/01/30 01:48:08
move to impl. drop last ','
chcunningham
2015/02/03 20:34:43
Done.
| |
| 40 // significant bits of the first byte. The index in this array corresponds | |
| 41 // to the duration of each frame of the packet in microseconds. See | |
| 42 // http://goo.gl/2RmoxA | |
| 43 const uint16 kOpusFrameDurationsMu[32] = { | |
| 44 10000, 20000, 40000, 60000, 10000, 20000, 40000, 60000, | |
| 45 10000, 20000, 40000, 60000, 10000, 20000, 10000, 20000, | |
| 46 2500, 5000, 10000, 20000, 2500, 5000, 10000, 20000, | |
| 47 2500, 5000, 10000, 20000, 2500, 5000, 10000, 20000, | |
| 48 }; | |
| 49 | |
| 38 private: | 50 private: |
| 39 // Helper class that manages per-track state. | 51 // Helper class that manages per-track state. |
| 40 class Track { | 52 class Track { |
| 41 public: | 53 public: |
| 42 Track(int track_num, | 54 Track(int track_num, |
| 43 bool is_video, | 55 bool is_video, |
| 44 base::TimeDelta default_duration, | 56 base::TimeDelta default_duration, |
| 45 const LogCB& log_cb); | 57 const LogCB& log_cb); |
| 46 ~Track(); | 58 ~Track(); |
| 47 | 59 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 126 |
| 115 // Buffers in (decode) timestamp order that were previously parsed into and | 127 // Buffers in (decode) timestamp order that were previously parsed into and |
| 116 // extracted from |buffers_|. Buffers are moved from |buffers_| to | 128 // extracted from |buffers_|. Buffers are moved from |buffers_| to |
| 117 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified | 129 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified |
| 118 // upper bound timestamp. Track users can therefore extract only those | 130 // upper bound timestamp. Track users can therefore extract only those |
| 119 // parsed buffers which are "ready" for emission (all before some maximum | 131 // parsed buffers which are "ready" for emission (all before some maximum |
| 120 // timestamp). | 132 // timestamp). |
| 121 BufferQueue ready_buffers_; | 133 BufferQueue ready_buffers_; |
| 122 | 134 |
| 123 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. | 135 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. |
| 124 base::TimeDelta default_duration_; | 136 base::TimeDelta default_duration_; |
|
wolenetz
2015/01/30 01:48:08
nit: Hmm. it seems the comments for how estimation
chcunningham
2015/02/03 20:34:43
I really pondered this (and we chatted). I think a
wolenetz
2015/02/03 22:47:01
Refactoring the estimation stuff to occur in OnBlo
| |
| 125 | 137 |
| 126 // If kNoTimestamp(), then a default value will be used. This estimate is | 138 // If kNoTimestamp(), then a default value will be used. This estimate is |
| 127 // the maximum duration seen or derived so far for this track, and is valid | 139 // the maximum duration seen or derived so far for this track, and is valid |
| 128 // only if |default_duration_| is kNoTimestamp(). | 140 // only if |default_duration_| is kNoTimestamp(). |
| 129 base::TimeDelta estimated_next_frame_duration_; | 141 base::TimeDelta estimated_next_frame_duration_; |
| 130 | 142 |
| 131 LogCB log_cb_; | 143 LogCB log_cb_; |
| 132 }; | 144 }; |
| 133 | 145 |
| 134 typedef std::map<int, Track> TextTrackMap; | 146 typedef std::map<int, Track> TextTrackMap; |
| 135 | 147 |
| 136 public: | 148 public: |
| 137 WebMClusterParser(int64 timecode_scale, | 149 WebMClusterParser(int64 timecode_scale, |
| 138 int audio_track_num, | 150 int audio_track_num, |
| 139 base::TimeDelta audio_default_duration, | 151 base::TimeDelta audio_default_duration, |
| 140 int video_track_num, | 152 int video_track_num, |
| 141 base::TimeDelta video_default_duration, | 153 base::TimeDelta video_default_duration, |
| 142 const WebMTracksParser::TextTracks& text_tracks, | 154 const WebMTracksParser::TextTracks& text_tracks, |
| 143 const std::set<int64>& ignored_tracks, | 155 const std::set<int64>& ignored_tracks, |
| 144 const std::string& audio_encryption_key_id, | 156 const std::string& audio_encryption_key_id, |
| 145 const std::string& video_encryption_key_id, | 157 const std::string& video_encryption_key_id, |
| 158 const AudioDecoderConfig& audio_config, | |
| 146 const LogCB& log_cb); | 159 const LogCB& log_cb); |
| 147 ~WebMClusterParser() override; | 160 ~WebMClusterParser() override; |
| 148 | 161 |
| 149 // Resets the parser state so it can accept a new cluster. | 162 // Resets the parser state so it can accept a new cluster. |
| 150 void Reset(); | 163 void Reset(); |
| 151 | 164 |
| 152 // Parses a WebM cluster element in |buf|. | 165 // Parses a WebM cluster element in |buf|. |
| 153 // | 166 // |
| 154 // Returns -1 if the parse fails. | 167 // Returns -1 if the parse fails. |
| 155 // Returns 0 if more data is needed. | 168 // Returns 0 if more data is needed. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 // bound.) | 233 // bound.) |
| 221 // Parse() or Reset() must be called between calls to UpdateReadyBuffers() to | 234 // 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_| | 235 // clear each track's ready buffers and to reset |ready_buffer_upper_bound_| |
| 223 // to kNoDecodeTimestamp(). | 236 // to kNoDecodeTimestamp(). |
| 224 void UpdateReadyBuffers(); | 237 void UpdateReadyBuffers(); |
| 225 | 238 |
| 226 // Search for the indicated track_num among the text tracks. Returns NULL | 239 // Search for the indicated track_num among the text tracks. Returns NULL |
| 227 // if that track num is not a text track. | 240 // if that track num is not a text track. |
| 228 Track* FindTextTrack(int track_num); | 241 Track* FindTextTrack(int track_num); |
| 229 | 242 |
| 243 // Attempts to read the duration from the encoded audio data, storing output | |
| 244 // in |duration| in microseconds. This obviously violates layering rules, but | |
| 245 // is useful for MSE to know duration in cases where it isn't explicitly given | |
| 246 // and cannot be calculated when for Blocks at the end of a Cluster (The next | |
|
wolenetz
2015/01/30 01:48:08
nits: grammar (when for), un-cap (The
chcunningham
2015/02/03 20:34:43
Done.
| |
| 247 // Cluster in playback-order may not be the next Cluster we parse, so we can't | |
| 248 // simply use the delta of the first Block in the next Cluster). Avoid calling | |
| 249 // if encrypted; may produce unexpected output. See implementation for | |
| 250 // supported codecs. | |
| 251 bool TryGetEncodedAudioDuration(const uint8* data, int size, int64* duration); | |
|
wolenetz
2015/01/30 01:48:08
What is bool retval?
chcunningham
2015/02/03 20:34:43
Now base::TimeDelta
| |
| 252 // Reads Opus packet header to determine packet duration. | |
|
wolenetz
2015/01/30 01:48:08
nit: insert blank link prior.
chcunningham
2015/02/03 20:34:43
Done.
| |
| 253 bool ReadOpusDuration(const uint8* data, int size, int64* duration); | |
| 254 | |
| 230 double timecode_multiplier_; // Multiplier used to convert timecodes into | 255 double timecode_multiplier_; // Multiplier used to convert timecodes into |
| 231 // microseconds. | 256 // microseconds. |
| 232 std::set<int64> ignored_tracks_; | 257 std::set<int64> ignored_tracks_; |
| 233 std::string audio_encryption_key_id_; | 258 std::string audio_encryption_key_id_; |
| 234 std::string video_encryption_key_id_; | 259 std::string video_encryption_key_id_; |
| 260 const AudioDecoderConfig& audio_config_; | |
|
wolenetz
2015/01/30 01:48:08
Do we need the whole config? Or just some specific
chcunningham
2015/02/03 20:34:43
Done. Now just taking in the codec.
| |
| 235 | 261 |
| 236 WebMListParser parser_; | 262 WebMListParser parser_; |
| 237 | 263 |
| 238 int64 last_block_timecode_; | 264 int64 last_block_timecode_; |
| 239 scoped_ptr<uint8[]> block_data_; | 265 scoped_ptr<uint8[]> block_data_; |
| 240 int block_data_size_; | 266 int block_data_size_; |
| 241 int64 block_duration_; | 267 int64 block_duration_; |
| 242 int64 block_add_id_; | 268 int64 block_add_id_; |
| 243 | 269 |
| 244 scoped_ptr<uint8[]> block_additional_data_; | 270 scoped_ptr<uint8[]> block_additional_data_; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 271 DecodeTimestamp ready_buffer_upper_bound_; | 297 DecodeTimestamp ready_buffer_upper_bound_; |
| 272 | 298 |
| 273 LogCB log_cb_; | 299 LogCB log_cb_; |
| 274 | 300 |
| 275 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); | 301 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); |
| 276 }; | 302 }; |
| 277 | 303 |
| 278 } // namespace media | 304 } // namespace media |
| 279 | 305 |
| 280 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ | 306 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ |
| OLD | NEW |