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
3 // found in the LICENSE file.
5 #include "media/base/stream_parser_buffer.h"
7 #include "base/logging.h"
8 #include "media/base/buffers.h"
12 static bool HasNestedFadeOutPreroll(
13 const std::vector<scoped_refptr<StreamParserBuffer> >& fade_out_preroll) {
14 for (size_t i = 0; i < fade_out_preroll.size(); ++i) {
15 if (!fade_out_preroll[i]->GetFadeOutPreroll().empty())
21 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CreateEOSBuffer() {
22 return make_scoped_refptr(new StreamParserBuffer(NULL, 0, NULL, 0, false,
23 DemuxerStream::UNKNOWN, 0));
26 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CopyFrom(
27 const uint8* data, int data_size, bool is_keyframe, Type type,
29 return make_scoped_refptr(
30 new StreamParserBuffer(data, data_size, NULL, 0, is_keyframe, type,
34 scoped_refptr<StreamParserBuffer> StreamParserBuffer::CopyFrom(
35 const uint8* data, int data_size,
36 const uint8* side_data, int side_data_size,
37 bool is_keyframe, Type type, TrackId track_id) {
38 return make_scoped_refptr(
39 new StreamParserBuffer(data, data_size, side_data, side_data_size,
40 is_keyframe, type, track_id));
43 base::TimeDelta StreamParserBuffer::GetDecodeTimestamp() const {
44 if (decode_timestamp_ == kNoTimestamp())
46 return decode_timestamp_;
49 void StreamParserBuffer::SetDecodeTimestamp(const base::TimeDelta& timestamp) {
50 decode_timestamp_ = timestamp;
53 StreamParserBuffer::StreamParserBuffer(const uint8* data, int data_size,
54 const uint8* side_data,
55 int side_data_size, bool is_keyframe,
56 Type type, TrackId track_id)
57 : DecoderBuffer(data, data_size, side_data, side_data_size),
58 is_keyframe_(is_keyframe),
59 decode_timestamp_(kNoTimestamp()),
60 config_id_(kInvalidConfigId),
63 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and
64 // duration to force clients to set them? Today they end up being zero which
65 // is both a common and valid value and could lead to bugs.
67 set_duration(kNoTimestamp());
71 StreamParserBuffer::~StreamParserBuffer() {
74 int StreamParserBuffer::GetConfigId() const {
78 void StreamParserBuffer::SetConfigId(int config_id) {
79 config_id_ = config_id;
82 const std::vector<scoped_refptr<StreamParserBuffer> >&
83 StreamParserBuffer::GetFadeOutPreroll() const {
84 return fade_out_preroll_;
87 void StreamParserBuffer::SetFadeOutPreroll(
88 const std::vector<scoped_refptr<StreamParserBuffer> >& fade_out_preroll) {
89 DCHECK(!HasNestedFadeOutPreroll(fade_out_preroll));
90 fade_out_preroll_ = fade_out_preroll;