OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "media/base/stream_parser_buffer.h" | 5 #include "media/base/stream_parser_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/base/buffers.h" | 8 #include "media/base/buffers.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 static scoped_refptr<StreamParserBuffer> CopyBuffer( | 12 static scoped_refptr<StreamParserBuffer> CopyBuffer( |
13 const StreamParserBuffer& buffer) { | 13 const StreamParserBuffer& buffer) { |
14 if (buffer.end_of_stream()) | 14 if (buffer.end_of_stream()) |
15 return StreamParserBuffer::CreateEOSBuffer(); | 15 return StreamParserBuffer::CreateEOSBuffer(); |
16 | 16 |
17 scoped_refptr<StreamParserBuffer> copied_buffer = | 17 scoped_refptr<StreamParserBuffer> copied_buffer = |
18 StreamParserBuffer::CopyFrom(buffer.data(), | 18 StreamParserBuffer::CopyFrom(buffer.data(), |
19 buffer.data_size(), | 19 buffer.data_size(), |
20 buffer.side_data(), | 20 buffer.side_data(), |
21 buffer.side_data_size(), | 21 buffer.side_data_size(), |
22 buffer.IsKeyframe(), | 22 buffer.is_key_frame(), |
23 buffer.type(), | 23 buffer.type(), |
24 buffer.track_id()); | 24 buffer.track_id()); |
25 copied_buffer->SetDecodeTimestamp(buffer.GetDecodeTimestamp()); | 25 copied_buffer->SetDecodeTimestamp(buffer.GetDecodeTimestamp()); |
26 copied_buffer->SetConfigId(buffer.GetConfigId()); | 26 copied_buffer->SetConfigId(buffer.GetConfigId()); |
27 copied_buffer->set_timestamp(buffer.timestamp()); | 27 copied_buffer->set_timestamp(buffer.timestamp()); |
28 copied_buffer->set_duration(buffer.duration()); | 28 copied_buffer->set_duration(buffer.duration()); |
29 copied_buffer->set_discard_padding(buffer.discard_padding()); | 29 copied_buffer->set_discard_padding(buffer.discard_padding()); |
30 copied_buffer->set_splice_timestamp(buffer.splice_timestamp()); | 30 copied_buffer->set_splice_timestamp(buffer.splice_timestamp()); |
31 const DecryptConfig* decrypt_config = buffer.decrypt_config(); | 31 const DecryptConfig* decrypt_config = buffer.decrypt_config(); |
32 if (decrypt_config) { | 32 if (decrypt_config) { |
33 copied_buffer->set_decrypt_config( | 33 copied_buffer->set_decrypt_config( |
34 make_scoped_ptr(new DecryptConfig(decrypt_config->key_id(), | 34 make_scoped_ptr(new DecryptConfig(decrypt_config->key_id(), |
35 decrypt_config->iv(), | 35 decrypt_config->iv(), |
36 decrypt_config->subsamples()))); | 36 decrypt_config->subsamples()))); |
37 } | 37 } |
38 | 38 |
39 return copied_buffer; | 39 return copied_buffer; |
40 } | 40 } |
41 | 41 |
42 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CreateEOSBuffer() { | 42 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CreateEOSBuffer() { |
43 return make_scoped_refptr(new StreamParserBuffer(NULL, 0, NULL, 0, false, | 43 return make_scoped_refptr(new StreamParserBuffer(NULL, 0, NULL, 0, false, |
44 DemuxerStream::UNKNOWN, 0)); | 44 DemuxerStream::UNKNOWN, 0)); |
45 } | 45 } |
46 | 46 |
47 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CopyFrom( | 47 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CopyFrom( |
48 const uint8* data, int data_size, bool is_keyframe, Type type, | 48 const uint8* data, int data_size, bool is_key_frame, Type type, |
49 TrackId track_id) { | 49 TrackId track_id) { |
50 return make_scoped_refptr( | 50 return make_scoped_refptr( |
51 new StreamParserBuffer(data, data_size, NULL, 0, is_keyframe, type, | 51 new StreamParserBuffer(data, data_size, NULL, 0, is_key_frame, type, |
52 track_id)); | 52 track_id)); |
53 } | 53 } |
54 | 54 |
55 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CopyFrom( | 55 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CopyFrom( |
56 const uint8* data, int data_size, | 56 const uint8* data, int data_size, |
57 const uint8* side_data, int side_data_size, | 57 const uint8* side_data, int side_data_size, |
58 bool is_keyframe, Type type, TrackId track_id) { | 58 bool is_key_frame, Type type, TrackId track_id) { |
59 return make_scoped_refptr( | 59 return make_scoped_refptr( |
60 new StreamParserBuffer(data, data_size, side_data, side_data_size, | 60 new StreamParserBuffer(data, data_size, side_data, side_data_size, |
61 is_keyframe, type, track_id)); | 61 is_key_frame, type, track_id)); |
62 } | 62 } |
63 | 63 |
64 DecodeTimestamp StreamParserBuffer::GetDecodeTimestamp() const { | 64 DecodeTimestamp StreamParserBuffer::GetDecodeTimestamp() const { |
65 if (decode_timestamp_ == kNoDecodeTimestamp()) | 65 if (decode_timestamp_ == kNoDecodeTimestamp()) |
66 return DecodeTimestamp::FromPresentationTime(timestamp()); | 66 return DecodeTimestamp::FromPresentationTime(timestamp()); |
67 return decode_timestamp_; | 67 return decode_timestamp_; |
68 } | 68 } |
69 | 69 |
70 void StreamParserBuffer::SetDecodeTimestamp(DecodeTimestamp timestamp) { | 70 void StreamParserBuffer::SetDecodeTimestamp(DecodeTimestamp timestamp) { |
71 decode_timestamp_ = timestamp; | 71 decode_timestamp_ = timestamp; |
72 if (preroll_buffer_.get()) | 72 if (preroll_buffer_.get()) |
73 preroll_buffer_->SetDecodeTimestamp(timestamp); | 73 preroll_buffer_->SetDecodeTimestamp(timestamp); |
74 } | 74 } |
75 | 75 |
76 StreamParserBuffer::StreamParserBuffer(const uint8* data, int data_size, | 76 StreamParserBuffer::StreamParserBuffer(const uint8* data, int data_size, |
77 const uint8* side_data, | 77 const uint8* side_data, |
78 int side_data_size, bool is_keyframe, | 78 int side_data_size, bool is_key_frame, |
79 Type type, TrackId track_id) | 79 Type type, TrackId track_id) |
80 : DecoderBuffer(data, data_size, side_data, side_data_size), | 80 : DecoderBuffer(data, data_size, side_data, side_data_size), |
81 is_keyframe_(is_keyframe), | |
82 decode_timestamp_(kNoDecodeTimestamp()), | 81 decode_timestamp_(kNoDecodeTimestamp()), |
83 config_id_(kInvalidConfigId), | 82 config_id_(kInvalidConfigId), |
84 type_(type), | 83 type_(type), |
85 track_id_(track_id) { | 84 track_id_(track_id) { |
86 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and | 85 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and |
87 // duration to force clients to set them? Today they end up being zero which | 86 // duration to force clients to set them? Today they end up being zero which |
88 // is both a common and valid value and could lead to bugs. | 87 // is both a common and valid value and could lead to bugs. |
89 if (data) { | 88 if (data) { |
90 set_duration(kNoTimestamp()); | 89 set_duration(kNoTimestamp()); |
91 } | 90 } |
| 91 |
| 92 if (is_key_frame) |
| 93 set_is_key_frame(true); |
92 } | 94 } |
93 | 95 |
94 StreamParserBuffer::~StreamParserBuffer() {} | 96 StreamParserBuffer::~StreamParserBuffer() {} |
95 | 97 |
96 int StreamParserBuffer::GetConfigId() const { | 98 int StreamParserBuffer::GetConfigId() const { |
97 return config_id_; | 99 return config_id_; |
98 } | 100 } |
99 | 101 |
100 void StreamParserBuffer::SetConfigId(int config_id) { | 102 void StreamParserBuffer::SetConfigId(int config_id) { |
101 config_id_ = config_id; | 103 config_id_ = config_id; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // Move over any preroll from this buffer. | 138 // Move over any preroll from this buffer. |
137 if (preroll_buffer_.get()) { | 139 if (preroll_buffer_.get()) { |
138 DCHECK(!overlapping_buffer->preroll_buffer_.get()); | 140 DCHECK(!overlapping_buffer->preroll_buffer_.get()); |
139 overlapping_buffer->preroll_buffer_.swap(preroll_buffer_); | 141 overlapping_buffer->preroll_buffer_.swap(preroll_buffer_); |
140 } | 142 } |
141 | 143 |
142 // Rewrite |this| buffer as a splice buffer. | 144 // Rewrite |this| buffer as a splice buffer. |
143 SetDecodeTimestamp(first_splice_buffer->GetDecodeTimestamp()); | 145 SetDecodeTimestamp(first_splice_buffer->GetDecodeTimestamp()); |
144 SetConfigId(first_splice_buffer->GetConfigId()); | 146 SetConfigId(first_splice_buffer->GetConfigId()); |
145 set_timestamp(first_splice_buffer->timestamp()); | 147 set_timestamp(first_splice_buffer->timestamp()); |
146 is_keyframe_ = first_splice_buffer->IsKeyframe(); | 148 set_is_key_frame(first_splice_buffer->is_key_frame()); |
147 type_ = first_splice_buffer->type(); | 149 type_ = first_splice_buffer->type(); |
148 track_id_ = first_splice_buffer->track_id(); | 150 track_id_ = first_splice_buffer->track_id(); |
149 set_splice_timestamp(overlapping_buffer->timestamp()); | 151 set_splice_timestamp(overlapping_buffer->timestamp()); |
150 | 152 |
151 // The splice duration is the duration of all buffers before the splice plus | 153 // The splice duration is the duration of all buffers before the splice plus |
152 // the highest ending timestamp after the splice point. | 154 // the highest ending timestamp after the splice point. |
153 DCHECK(overlapping_buffer->duration() > base::TimeDelta()); | 155 DCHECK(overlapping_buffer->duration() > base::TimeDelta()); |
154 DCHECK(pre_splice_buffers.back()->duration() > base::TimeDelta()); | 156 DCHECK(pre_splice_buffers.back()->duration() > base::TimeDelta()); |
155 set_duration( | 157 set_duration( |
156 std::max(overlapping_buffer->timestamp() + overlapping_buffer->duration(), | 158 std::max(overlapping_buffer->timestamp() + overlapping_buffer->duration(), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 std::make_pair(kInfiniteDuration(), base::TimeDelta())); | 197 std::make_pair(kInfiniteDuration(), base::TimeDelta())); |
196 } | 198 } |
197 | 199 |
198 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { | 200 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { |
199 DecoderBuffer::set_timestamp(timestamp); | 201 DecoderBuffer::set_timestamp(timestamp); |
200 if (preroll_buffer_.get()) | 202 if (preroll_buffer_.get()) |
201 preroll_buffer_->set_timestamp(timestamp); | 203 preroll_buffer_->set_timestamp(timestamp); |
202 } | 204 } |
203 | 205 |
204 } // namespace media | 206 } // namespace media |
OLD | NEW |