OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/webm/webm_cluster_parser.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "media/base/data_buffer.h" | |
9 #include "media/webm/webm_constants.h" | |
10 | |
11 namespace media { | |
12 | |
scherkus (not reviewing)
2011/06/24 18:27:37
extra line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
| |
13 | |
14 WebMClusterParser::WebMClusterParser(int64 timecode_scale, | |
15 int audio_track_num, | |
16 base::TimeDelta audio_default_duration, | |
17 int video_track_num, | |
18 base::TimeDelta video_default_duration) | |
19 : timecode_multiplier_(timecode_scale / 1000.0), | |
20 audio_track_num_(audio_track_num), | |
21 audio_default_duration_(audio_default_duration), | |
22 video_track_num_(video_track_num), | |
23 video_default_duration_(video_default_duration), | |
24 cluster_timecode_(-1) { | |
25 } | |
26 | |
27 WebMClusterParser::~WebMClusterParser() {} | |
28 | |
29 void WebMClusterParser::Reset() { | |
30 cluster_timecode_ = -1; | |
31 audio_buffers_.clear(); | |
32 video_buffers_.clear(); | |
33 } | |
34 | |
35 int WebMClusterParser::Parse(const uint8* buf, int size) { | |
36 return WebMParseListElement(buf, size, kWebMIdCluster, 1, this); | |
37 } | |
38 | |
39 const WebMClusterParser::BufferQueue& WebMClusterParser::audio_buffers() const { | |
40 return audio_buffers_; | |
41 }; | |
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.
| |
42 | |
43 const WebMClusterParser::BufferQueue& WebMClusterParser::video_buffers() const { | |
44 return video_buffers_; | |
45 }; | |
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.
| |
46 | |
47 bool WebMClusterParser::OnListStart(int id) { | |
48 if (id == kWebMIdCluster) | |
49 cluster_timecode_ = -1; | |
50 | |
51 return true; | |
52 } | |
53 | |
54 bool WebMClusterParser::OnListEnd(int id) { | |
55 if (id == kWebMIdCluster) | |
56 cluster_timecode_ = -1; | |
57 | |
58 return true; | |
59 } | |
60 | |
61 bool WebMClusterParser::OnUInt(int id, int64 val) { | |
62 if (id == kWebMIdTimecode) { | |
63 if (cluster_timecode_ != -1) | |
64 return false; | |
65 | |
66 cluster_timecode_ = val; | |
67 } | |
68 | |
69 return true; | |
70 } | |
71 | |
72 bool WebMClusterParser::OnFloat(int id, double val) { | |
73 VLOG(1) << "Unexpected float element with ID " << std::hex << id; | |
74 return false; | |
75 } | |
76 | |
77 bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) { | |
78 VLOG(1) << "Unexpected binary element with ID " << std::hex << id; | |
79 return false; | |
80 } | |
81 | |
82 bool WebMClusterParser::OnString(int id, const std::string& str) { | |
83 VLOG(1) << "Unexpected string element with ID " << std::hex << id; | |
84 return false; | |
85 } | |
86 | |
87 bool WebMClusterParser::OnSimpleBlock(int track_num, int timecode, | |
88 int flags, | |
89 const uint8* data, int size) { | |
90 if (cluster_timecode_ == -1) { | |
91 VLOG(1) << "Got SimpleBlock before cluster timecode."; | |
92 return false; | |
93 } | |
94 | |
95 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( | |
96 (cluster_timecode_ + timecode) * timecode_multiplier_); | |
97 | |
98 scoped_refptr<Buffer> buffer(CreateBuffer(data, size)); | |
99 buffer->SetTimestamp(timestamp); | |
100 | |
101 if (track_num == audio_track_num_) { | |
102 buffer->SetDuration(audio_default_duration_); | |
103 audio_buffers_.push_back(buffer); | |
104 return true; | |
105 } | |
106 | |
107 if (track_num == video_track_num_) { | |
108 buffer->SetDuration(video_default_duration_); | |
109 video_buffers_.push_back(buffer); | |
110 return true; | |
111 } | |
112 | |
113 VLOG(1) << "Unexpected track number " << track_num; | |
114 return false; | |
115 } | |
116 | |
117 | |
scherkus (not reviewing)
2011/06/24 18:27:37
extra line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
| |
118 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.
| |
119 scoped_array<uint8> buf(new uint8[size]); | |
120 memcpy(buf.get(), data, size); | |
121 return new DataBuffer(buf.release(), size); | |
122 } | |
123 | |
124 | |
scherkus (not reviewing)
2011/06/24 18:27:37
extra line
acolwell GONE FROM CHROMIUM
2011/06/27 23:48:25
Done.
| |
125 } // namespace media | |
OLD | NEW |