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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: media/formats/webm/webm_cluster_parser.h
diff --git a/media/formats/webm/webm_cluster_parser.h b/media/formats/webm/webm_cluster_parser.h
index 2af102eaa0ce58b28909a6aa15fffd1bdbe4ed00..a6466056e63fa0a5e0ad88b511dd4a37b1ca567c 100644
--- a/media/formats/webm/webm_cluster_parser.h
+++ b/media/formats/webm/webm_cluster_parser.h
@@ -11,6 +11,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
+#include "media/base/audio_decoder_config.h"
#include "media/base/media_export.h"
#include "media/base/media_log.h"
#include "media/base/stream_parser.h"
@@ -28,13 +29,17 @@ class MEDIA_EXPORT WebMClusterParser : public WebMParserClient {
// Arbitrarily-chosen numbers to estimate the duration of a buffer if none is
// set and there is not enough information to get a better estimate.
- // TODO(wolenetz/acolwell): Parse audio codebook to determine missing audio
- // frame durations. See http://crbug.com/351166.
enum {
kDefaultAudioBufferDurationInMs = 23, // Common 1k samples @44.1kHz
kDefaultVideoBufferDurationInMs = 42 // Low 24fps to reduce stalls
};
+ // Opus packets encode the duration and other parameters in the 5 most
+ // significant bits of the first byte. The index in this array corresponds
+ // to the duration of each frame of the packet in microseconds. See
+ // 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.
+ static const uint16 kOpusFrameDurationsMu[];
wolenetz 2015/02/03 22:47:02 _t
chcunningham 2015/02/05 02:48:22 Done.
+
private:
// Helper class that manages per-track state.
class Track {
@@ -143,6 +148,7 @@ class MEDIA_EXPORT WebMClusterParser : public WebMParserClient {
const std::set<int64>& ignored_tracks,
const std::string& audio_encryption_key_id,
const std::string& video_encryption_key_id,
+ const AudioCodec audio_codec_,
const LogCB& log_cb);
~WebMClusterParser() override;
@@ -227,11 +233,24 @@ class MEDIA_EXPORT WebMClusterParser : public WebMParserClient {
// if that track num is not a text track.
Track* FindTextTrack(int track_num);
+ // Attempts to read the duration from the encoded audio data. This obviously
+ // violates layering rules, but is useful for MSE to know duration in cases
+ // where it isn't explicitly given and cannot be calculated for Blocks at the
+ // end of a Cluster (the next Cluster in playback-order may not be the next
+ // Cluster we parse, so we can't simply use the delta of the first Block in
+ // the next Cluster). Avoid calling if encrypted; may produce unexpected
+ // 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.
+ 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.
+
+ // 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.
+ 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.
+
double timecode_multiplier_; // Multiplier used to convert timecodes into
// microseconds.
std::set<int64> ignored_tracks_;
std::string audio_encryption_key_id_;
std::string video_encryption_key_id_;
+ const AudioCodec audio_codec_;
WebMListParser parser_;

Powered by Google App Engine
This is Rietveld 408576698