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() {
36 return DemuxerStream::TEXT
;
39 bool FakeTextTrackStream::SupportsConfigChanges() { return false; }
41 void FakeTextTrackStream::SatisfyPendingRead(
42 const base::TimeDelta
& start
,
43 const base::TimeDelta
& duration
,
44 const std::string
& id
,
45 const std::string
& content
,
46 const std::string
& settings
) {
47 DCHECK(!read_cb_
.is_null());
49 const uint8
* const data_buf
= reinterpret_cast<const uint8
*>(content
.data());
50 const int data_len
= static_cast<int>(content
.size());
52 std::vector
<uint8
> side_data
;
53 MakeSideData(id
.begin(), id
.end(),
54 settings
.begin(), settings
.end(),
57 const uint8
* const sd_buf
= &side_data
[0];
58 const int sd_len
= static_cast<int>(side_data
.size());
60 scoped_refptr
<DecoderBuffer
> buffer
;
61 buffer
= DecoderBuffer::CopyFrom(data_buf
, data_len
, sd_buf
, sd_len
);
63 buffer
->set_timestamp(start
);
64 buffer
->set_duration(duration
);
66 base::ResetAndReturn(&read_cb_
).Run(kOk
, buffer
);
69 void FakeTextTrackStream::AbortPendingRead() {
70 DCHECK(!read_cb_
.is_null());
71 base::ResetAndReturn(&read_cb_
).Run(kAborted
, NULL
);
74 void FakeTextTrackStream::SendEosNotification() {
75 DCHECK(!read_cb_
.is_null());
76 base::ResetAndReturn(&read_cb_
).Run(kOk
, DecoderBuffer::CreateEOSBuffer());
79 void FakeTextTrackStream::Stop() {
81 if (!read_cb_
.is_null())