OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include "media/base/fake_text_track_stream.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 9 #include "media/base/decoder_buffer.h" |
| 10 #include "media/filters/webvtt_util.h" |
| 11 |
| 12 namespace media { |
| 13 |
| 14 FakeTextTrackStream::FakeTextTrackStream() |
| 15 : message_loop_(base::MessageLoopProxy::current()), |
| 16 stopping_(false) { |
| 17 } |
| 18 |
| 19 FakeTextTrackStream::~FakeTextTrackStream() { |
| 20 DCHECK(read_cb_.is_null()); |
| 21 } |
| 22 |
| 23 void FakeTextTrackStream::Read(const ReadCB& read_cb) { |
| 24 DCHECK(!read_cb.is_null()); |
| 25 DCHECK(read_cb_.is_null()); |
| 26 read_cb_ = read_cb; |
| 27 |
| 28 if (stopping_) { |
| 29 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 30 &FakeTextTrackStream::AbortPendingRead, base::Unretained(this))); |
| 31 } |
| 32 } |
| 33 |
| 34 DemuxerStream::Type FakeTextTrackStream::type() { |
| 35 return DemuxerStream::TEXT; |
| 36 } |
| 37 |
| 38 void FakeTextTrackStream::SatisfyPendingRead( |
| 39 const base::TimeDelta& start, |
| 40 const base::TimeDelta& duration, |
| 41 const std::string& id, |
| 42 const std::string& content, |
| 43 const std::string& settings) { |
| 44 DCHECK(!read_cb_.is_null()); |
| 45 |
| 46 const uint8* const data = reinterpret_cast<const uint8*>(content.data()); |
| 47 |
| 48 std::vector<uint8> side_data; |
| 49 MakeSideData(id.begin(), id.end(), |
| 50 settings.begin(), settings.end(), |
| 51 &side_data); |
| 52 |
| 53 scoped_refptr<DecoderBuffer> buffer; |
| 54 |
| 55 buffer = DecoderBuffer::CopyFrom(data, |
| 56 content.size(), |
| 57 side_data.data(), |
| 58 side_data.size()); |
| 59 |
| 60 buffer->set_timestamp(start); |
| 61 buffer->set_duration(duration); |
| 62 |
| 63 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); |
| 64 } |
| 65 |
| 66 void FakeTextTrackStream::AbortPendingRead() { |
| 67 DCHECK(!read_cb_.is_null()); |
| 68 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
| 69 } |
| 70 |
| 71 void FakeTextTrackStream::SendEosNotification() { |
| 72 DCHECK(!read_cb_.is_null()); |
| 73 base::ResetAndReturn(&read_cb_).Run(kOk, DecoderBuffer::CreateEOSBuffer()); |
| 74 } |
| 75 |
| 76 void FakeTextTrackStream::Stop() { |
| 77 stopping_ = true; |
| 78 if (!read_cb_.is_null()) |
| 79 AbortPendingRead(); |
| 80 } |
| 81 |
| 82 } // namespace media |
OLD | NEW |