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

Unified Diff: media/formats/webm/webm_cluster_parser.cc

Issue 883403002: Parsing of encoded duration for unencrypted opus streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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.cc
diff --git a/media/formats/webm/webm_cluster_parser.cc b/media/formats/webm/webm_cluster_parser.cc
index 6784776a0e029e0c21d168391532087b8a43fa6b..7e4b7d595e27c12b0d240d22c7483888fe48a7c5 100644
--- a/media/formats/webm/webm_cluster_parser.cc
+++ b/media/formats/webm/webm_cluster_parser.cc
@@ -27,11 +27,13 @@ WebMClusterParser::WebMClusterParser(
const std::set<int64>& ignored_tracks,
const std::string& audio_encryption_key_id,
const std::string& video_encryption_key_id,
+ const AudioDecoderConfig& audio_config,
const LogCB& log_cb)
: timecode_multiplier_(timecode_scale / 1000.0),
ignored_tracks_(ignored_tracks),
audio_encryption_key_id_(audio_encryption_key_id),
video_encryption_key_id_(video_encryption_key_id),
+ audio_config_(audio_config),
chcunningham 2015/01/29 22:14:20 I'm not doing anything with this in ::Reset. Shoul
wolenetz 2015/01/30 01:48:08 ::Reset() is only for "let's parse another cluster
chcunningham 2015/02/03 20:34:43 Acknowledged.
parser_(kWebMIdCluster, this),
last_block_timecode_(-1),
block_data_size_(-1),
@@ -140,6 +142,57 @@ WebMClusterParser::GetTextBuffers() {
return text_buffers_map_;
}
+bool WebMClusterParser::TryGetEncodedAudioDuration(const uint8* data,
wolenetz 2015/01/30 01:48:07 I suggest using a base::TimeDelta duration as retv
chcunningham 2015/02/03 20:34:42 Done, but a question about asserts. I haven't yet
wolenetz 2015/02/03 22:47:00 For now, yeah, let frame processor/etc deal with 0
+ int size,
+ int64* duration) {
+ if (audio_config_.codec() == kCodecOpus) {
+ return ReadOpusDuration(data, size, duration);
+ }
+
+ return false;
+}
+
+bool WebMClusterParser::ReadOpusDuration(const uint8* data,
wolenetz 2015/01/30 01:48:08 ditto on retval comment.
chcunningham 2015/02/03 20:34:42 Done.
+ int size,
+ int64* duration) {
+ if (size < 1) {
+ MEDIA_LOG(log_cb_) << "Invalid zero-byte Opus packet.";
wolenetz 2015/01/30 01:48:07 Could it be possible that an append one-byte-at-a-
wolenetz 2015/01/30 20:46:12 nm. OnBlock is done on complete block, not partial
chcunningham 2015/02/03 20:34:42 Acknowledged.
+ return false;
+ }
+
+ // Frame count type described by last 2 bits of Opus TOC byte.
+ int frame_count_type = data[0] & 0x03;
+
+ int frame_count = 0;
+ switch (frame_count_type) {
+ case 0:
+ frame_count = 1;
+ break;
+ case 1:
+ case 2:
+ frame_count = 2;
+ break;
+ case 3:
+ // Type 3 indicates an arbitrary frame count described in the next byte.
+ if (size < 2) {
+ MEDIA_LOG(log_cb_) << "Second byte missing from 'Code 3' Opus packet.";
wolenetz 2015/01/30 01:48:08 ditto: protect against spurious log?
wolenetz 2015/01/30 20:46:12 ditto nm
chcunningham 2015/02/03 20:34:42 Acknowledged.
+ return false;
+ }
+ frame_count = data[1] & 0x3f;
+ DCHECK_GE(frame_count, 1);
+ break;
+ default:
+ MEDIA_LOG(log_cb_) << "Unexpected Opus frame count type: "
+ << frame_count_type;
+ return false;
+ }
+
+ int opusConfig = (data[0] & 0xf8) >> 3;
wolenetz 2015/01/30 20:46:12 nit: put "magic" 0xf8 and others like that into an
chcunningham 2015/02/03 20:34:43 Done, sort of. Did it right here in the .cc - head
wolenetz 2015/02/03 22:47:00 I'm not sure how an enum consumes more mem that a
+ *duration = kOpusFrameDurationsMu[opusConfig] * frame_count;
wolenetz 2015/01/30 01:48:08 frame_count could be zero in a "code 3 packet". Gu
wolenetz 2015/01/30 20:46:12 The strange wording is clarified elsewhere in that
chcunningham 2015/02/03 20:34:42 Agree this is hard to read. I think I have an inte
wolenetz 2015/02/03 22:47:00 I agree. See my comment on current PS.
+
+ return true;
+}
+
WebMParserClient* WebMClusterParser::OnListStart(int id) {
if (id == kWebMIdCluster) {
cluster_timecode_ = -1;
@@ -324,9 +377,13 @@ bool WebMClusterParser::OnBlock(bool is_simple_block, int track_num,
Track* track = NULL;
StreamParserBuffer::Type buffer_type = DemuxerStream::AUDIO;
std::string encryption_key_id;
+ int64 encoded_duration = -1;
wolenetz 2015/01/30 01:48:08 ditto: base::TimeDelta please
chcunningham 2015/02/03 20:34:42 Done.
if (track_num == audio_.track_num()) {
track = &audio_;
encryption_key_id = audio_encryption_key_id_;
+ if (encryption_key_id.empty()) {
+ TryGetEncodedAudioDuration(data, size, &encoded_duration);
wolenetz 2015/01/30 01:48:08 note the retval was ignored previously... not sure
chcunningham 2015/02/03 20:34:42 Done.
+ }
wolenetz 2015/01/30 01:48:08 nit: no {} necessary for one-line block here. I'm
wolenetz 2015/01/30 01:48:08 I'd like to see at least DVLOG for audio block if
chcunningham 2015/02/03 20:34:42 It became a mutli-line block after adding the DVLO
chcunningham 2015/02/03 20:34:42 Done. How does 10ms for a threshold sound?
wolenetz 2015/02/03 22:47:00 See my comment on current PS.
} else if (track_num == video_.track_num()) {
track = &video_;
encryption_key_id = video_encryption_key_id_;
@@ -407,7 +464,9 @@ bool WebMClusterParser::OnBlock(bool is_simple_block, int track_num,
if (cluster_start_time_ == kNoTimestamp())
cluster_start_time_ = timestamp;
- if (block_duration >= 0) {
+ if (encoded_duration >= 0) {
+ buffer->set_duration(base::TimeDelta::FromMicroseconds(encoded_duration));
+ } else if (block_duration >= 0) {
buffer->set_duration(base::TimeDelta::FromMicroseconds(
block_duration * timecode_multiplier_));
} else {

Powered by Google App Engine
This is Rietveld 408576698