Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1624)

Side by Side Diff: media/filters/text_decoder_impl.cc

Issue 23702007: Render inband text tracks in the media pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: incorporate aaron's comments (9/28) Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/filters/text_decoder_impl.h"
6
7 #include "base/callback_helpers.h"
8 #include "media/base/bind_to_loop.h"
9 #include "media/base/decoder_buffer.h"
10 #include "media/base/demuxer.h"
11 #include "media/base/text_cue.h"
12
13 namespace media {
14
15 TextDecoderImpl::TextDecoderImpl(
16 const scoped_refptr<base::MessageLoopProxy>& message_loop)
17 : message_loop_(message_loop),
18 weak_factory_(this) {
19 }
20
21 TextDecoderImpl::~TextDecoderImpl() {
22 }
23
24 void TextDecoderImpl::Initialize() {
25 DCHECK(message_loop_->BelongsToCurrentThread());
26 weak_this_ = weak_factory_.GetWeakPtr();
27 }
28
29 void TextDecoderImpl::Read(DemuxerStream* stream, const ReadCB& read_cb) {
30 DCHECK(message_loop_->BelongsToCurrentThread());
31 DCHECK(!read_cb.is_null());
32
33 ReadCB& cb = read_callbacks_[stream];
34 CHECK(cb.is_null()) << "Overlapping decodes are not supported.";
35
36 cb = BindToCurrentLoop(read_cb);
37
38 stream->Read(base::Bind(
39 &TextDecoderImpl::BufferReady, weak_this_, stream));
40 }
41
42 void TextDecoderImpl::BufferReady(
acolwell GONE FROM CHROMIUM 2013/10/08 15:45:24 I don't think you need this class. This method see
Matthew Heaney (Chromium) 2013/10/13 05:30:17 Done.
43 DemuxerStream* stream,
44 DemuxerStream::Status status,
45 const scoped_refptr<DecoderBuffer>& input) {
46 DCHECK(message_loop_->BelongsToCurrentThread());
47
48 ReadCB& read_cb = read_callbacks_[stream];
49 DCHECK(!read_cb.is_null());
50
51 if (status == DemuxerStream::kAborted) {
52 DCHECK(!input.get());
53 base::ResetAndReturn(&read_cb).Run(stream, NULL);
54 return;
55 }
56
57 if (input->end_of_stream()) {
58 base::ResetAndReturn(&read_cb).Run(stream, NULL);
59 return;
60 }
61
62 DCHECK_EQ(status, DemuxerStream::kOk);
63 DCHECK(input.get());
64 DCHECK_GE(input->side_data_size(), 2);
65
66 // The side data contains both the cue id and cue settings,
67 // each terminated with a NUL.
68 const char* id_ptr = reinterpret_cast<const char*>(input->side_data());
69 size_t id_len = strlen(id_ptr);
70 std::string id(id_ptr, id_len);
71
72 const char* settings_ptr = id_ptr + id_len + 1;
73 size_t settings_len = strlen(settings_ptr);
74 std::string settings(settings_ptr, settings_len);
75
76 // The cue payload is stored in the data-part of the input buffer.
77 std::string text(input->data(), input->data() + input->data_size());
78
79 scoped_refptr<TextCue> text_cue(
80 new TextCue(input->timestamp(),
81 input->duration(),
82 id,
83 settings,
84 text));
85
86 base::ResetAndReturn(&read_cb).Run(stream, text_cue);
87 }
88
89 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698