Index: media/webm/webm_cluster_parser.cc |
diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..457e2f0f39a45000814f738c381486a8c1cb26c3 |
--- /dev/null |
+++ b/media/webm/webm_cluster_parser.cc |
@@ -0,0 +1,125 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/webm/webm_cluster_parser.h" |
+ |
+#include "base/logging.h" |
+#include "media/base/data_buffer.h" |
+#include "media/webm/webm_constants.h" |
+ |
+namespace media { |
+ |
scherkus (not reviewing)
2011/06/24 18:27:37
extra line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
|
+ |
+WebMClusterParser::WebMClusterParser(int64 timecode_scale, |
+ int audio_track_num, |
+ base::TimeDelta audio_default_duration, |
+ int video_track_num, |
+ base::TimeDelta video_default_duration) |
+ : timecode_multiplier_(timecode_scale / 1000.0), |
+ audio_track_num_(audio_track_num), |
+ audio_default_duration_(audio_default_duration), |
+ video_track_num_(video_track_num), |
+ video_default_duration_(video_default_duration), |
+ cluster_timecode_(-1) { |
+} |
+ |
+WebMClusterParser::~WebMClusterParser() {} |
+ |
+void WebMClusterParser::Reset() { |
+ cluster_timecode_ = -1; |
+ audio_buffers_.clear(); |
+ video_buffers_.clear(); |
+} |
+ |
+int WebMClusterParser::Parse(const uint8* buf, int size) { |
+ return WebMParseListElement(buf, size, kWebMIdCluster, 1, this); |
+} |
+ |
+const WebMClusterParser::BufferQueue& WebMClusterParser::audio_buffers() const { |
+ return audio_buffers_; |
+}; |
scherkus (not reviewing)
2011/06/24 18:27:37
remove semicolon OR you can inline this in .h sinc
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
|
+ |
+const WebMClusterParser::BufferQueue& WebMClusterParser::video_buffers() const { |
+ return video_buffers_; |
+}; |
scherkus (not reviewing)
2011/06/24 18:27:37
remove semicolon OR you can inline this in .h sinc
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
|
+ |
+bool WebMClusterParser::OnListStart(int id) { |
+ if (id == kWebMIdCluster) |
+ cluster_timecode_ = -1; |
+ |
+ return true; |
+} |
+ |
+bool WebMClusterParser::OnListEnd(int id) { |
+ if (id == kWebMIdCluster) |
+ cluster_timecode_ = -1; |
+ |
+ return true; |
+} |
+ |
+bool WebMClusterParser::OnUInt(int id, int64 val) { |
+ if (id == kWebMIdTimecode) { |
+ if (cluster_timecode_ != -1) |
+ return false; |
+ |
+ cluster_timecode_ = val; |
+ } |
+ |
+ return true; |
+} |
+ |
+bool WebMClusterParser::OnFloat(int id, double val) { |
+ VLOG(1) << "Unexpected float element with ID " << std::hex << id; |
+ return false; |
+} |
+ |
+bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) { |
+ VLOG(1) << "Unexpected binary element with ID " << std::hex << id; |
+ return false; |
+} |
+ |
+bool WebMClusterParser::OnString(int id, const std::string& str) { |
+ VLOG(1) << "Unexpected string element with ID " << std::hex << id; |
+ return false; |
+} |
+ |
+bool WebMClusterParser::OnSimpleBlock(int track_num, int timecode, |
+ int flags, |
+ const uint8* data, int size) { |
+ if (cluster_timecode_ == -1) { |
+ VLOG(1) << "Got SimpleBlock before cluster timecode."; |
+ return false; |
+ } |
+ |
+ base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
+ (cluster_timecode_ + timecode) * timecode_multiplier_); |
+ |
+ scoped_refptr<Buffer> buffer(CreateBuffer(data, size)); |
+ buffer->SetTimestamp(timestamp); |
+ |
+ if (track_num == audio_track_num_) { |
+ buffer->SetDuration(audio_default_duration_); |
+ audio_buffers_.push_back(buffer); |
+ return true; |
+ } |
+ |
+ if (track_num == video_track_num_) { |
+ buffer->SetDuration(video_default_duration_); |
+ video_buffers_.push_back(buffer); |
+ return true; |
+ } |
+ |
+ VLOG(1) << "Unexpected track number " << track_num; |
+ return false; |
+} |
+ |
+ |
scherkus (not reviewing)
2011/06/24 18:27:37
extra line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
|
+Buffer* WebMClusterParser::CreateBuffer(const uint8* data, size_t size) const { |
scherkus (not reviewing)
2011/06/24 18:27:37
if you want this can be static
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
|
+ scoped_array<uint8> buf(new uint8[size]); |
+ memcpy(buf.get(), data, size); |
+ return new DataBuffer(buf.release(), size); |
+} |
+ |
+ |
scherkus (not reviewing)
2011/06/24 18:27:37
extra line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
|
+} // namespace media |