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 "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "media/base/decoder_buffer.h"
12 #include "media/filters/webvtt_util.h"
16 FakeTextTrackStream::FakeTextTrackStream()
17 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
21 FakeTextTrackStream::~FakeTextTrackStream() {
22 DCHECK(read_cb_
.is_null());
25 void FakeTextTrackStream::Read(const ReadCB
& read_cb
) {
26 DCHECK(!read_cb
.is_null());
27 DCHECK(read_cb_
.is_null());
32 task_runner_
->PostTask(FROM_HERE
, base::Bind(
33 &FakeTextTrackStream::AbortPendingRead
, base::Unretained(this)));
37 DemuxerStream::Type
FakeTextTrackStream::type() const {
38 return DemuxerStream::TEXT
;
41 bool FakeTextTrackStream::SupportsConfigChanges() { return false; }
43 VideoRotation
FakeTextTrackStream::video_rotation() {
44 return VIDEO_ROTATION_0
;
47 void FakeTextTrackStream::SatisfyPendingRead(
48 const base::TimeDelta
& start
,
49 const base::TimeDelta
& duration
,
50 const std::string
& id
,
51 const std::string
& content
,
52 const std::string
& settings
) {
53 DCHECK(!read_cb_
.is_null());
55 const uint8
* const data_buf
= reinterpret_cast<const uint8
*>(content
.data());
56 const int data_len
= static_cast<int>(content
.size());
58 std::vector
<uint8
> side_data
;
59 MakeSideData(id
.begin(), id
.end(),
60 settings
.begin(), settings
.end(),
63 const uint8
* const sd_buf
= &side_data
[0];
64 const int sd_len
= static_cast<int>(side_data
.size());
66 scoped_refptr
<DecoderBuffer
> buffer
;
67 buffer
= DecoderBuffer::CopyFrom(data_buf
, data_len
, sd_buf
, sd_len
);
69 buffer
->set_timestamp(start
);
70 buffer
->set_duration(duration
);
72 // Assume all fake text buffers are keyframes.
73 buffer
->set_is_key_frame(true);
75 base::ResetAndReturn(&read_cb_
).Run(kOk
, buffer
);
78 void FakeTextTrackStream::AbortPendingRead() {
79 DCHECK(!read_cb_
.is_null());
80 base::ResetAndReturn(&read_cb_
).Run(kAborted
, NULL
);
83 void FakeTextTrackStream::SendEosNotification() {
84 DCHECK(!read_cb_
.is_null());
85 base::ResetAndReturn(&read_cb_
).Run(kOk
, DecoderBuffer::CreateEOSBuffer());
88 void FakeTextTrackStream::Stop() {
90 if (!read_cb_
.is_null())