1 // Copyright 2013 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/fake_text_track_stream.h"
8 #include "base/callback_helpers.h"
9 #include "media/base/decoder_buffer.h"
10 #include "media/filters/webvtt_util.h"
14 FakeTextTrackStream::FakeTextTrackStream()
15 : task_runner_(base::MessageLoopProxy::current()),
19 FakeTextTrackStream::~FakeTextTrackStream() {
20 DCHECK(read_cb_
.is_null());
23 void FakeTextTrackStream::Read(const ReadCB
& read_cb
) {
24 DCHECK(!read_cb
.is_null());
25 DCHECK(read_cb_
.is_null());
30 task_runner_
->PostTask(FROM_HERE
, base::Bind(
31 &FakeTextTrackStream::AbortPendingRead
, base::Unretained(this)));
35 DemuxerStream::Type
FakeTextTrackStream::type() const {
36 return DemuxerStream::TEXT
;
39 bool FakeTextTrackStream::SupportsConfigChanges() { return false; }
41 VideoRotation
FakeTextTrackStream::video_rotation() {
42 return VIDEO_ROTATION_0
;
45 void FakeTextTrackStream::SatisfyPendingRead(
46 const base::TimeDelta
& start
,
47 const base::TimeDelta
& duration
,
48 const std::string
& id
,
49 const std::string
& content
,
50 const std::string
& settings
) {
51 DCHECK(!read_cb_
.is_null());
53 const uint8
* const data_buf
= reinterpret_cast<const uint8
*>(content
.data());
54 const int data_len
= static_cast<int>(content
.size());
56 std::vector
<uint8
> side_data
;
57 MakeSideData(id
.begin(), id
.end(),
58 settings
.begin(), settings
.end(),
61 const uint8
* const sd_buf
= &side_data
[0];
62 const int sd_len
= static_cast<int>(side_data
.size());
64 scoped_refptr
<DecoderBuffer
> buffer
;
65 buffer
= DecoderBuffer::CopyFrom(data_buf
, data_len
, sd_buf
, sd_len
);
67 buffer
->set_timestamp(start
);
68 buffer
->set_duration(duration
);
70 // Assume all fake text buffers are keyframes.
71 buffer
->set_is_key_frame(true);
73 base::ResetAndReturn(&read_cb_
).Run(kOk
, buffer
);
76 void FakeTextTrackStream::AbortPendingRead() {
77 DCHECK(!read_cb_
.is_null());
78 base::ResetAndReturn(&read_cb_
).Run(kAborted
, NULL
);
81 void FakeTextTrackStream::SendEosNotification() {
82 DCHECK(!read_cb_
.is_null());
83 base::ResetAndReturn(&read_cb_
).Run(kOk
, DecoderBuffer::CreateEOSBuffer());
86 void FakeTextTrackStream::Stop() {
88 if (!read_cb_
.is_null())