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 #ifndef MEDIA_BASE_TEXT_RENDERER_H_ | |
6 #define MEDIA_BASE_TEXT_RENDERER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "media/base/demuxer_stream.h" | |
14 #include "media/base/media_export.h" | |
15 #include "media/base/pipeline_status.h" | |
16 #include "media/base/text_track.h" | |
17 | |
18 namespace base { | |
19 class MessageLoopProxy; | |
20 } | |
21 | |
22 namespace media { | |
23 | |
24 class TextCue; | |
25 | |
26 // Receives the decoded cues from the upstream decoder, and passes them | |
acolwell GONE FROM CHROMIUM
2013/10/14 20:42:24
nit: Update comment. There isn't a decoder anymore
Matthew Heaney (Chromium)
2013/10/17 05:46:44
Done.
| |
27 // onto the TextTrack object associated with each demuxer text stream. | |
28 class MEDIA_EXPORT TextRenderer { | |
29 public: | |
30 // |message_loop| is the thread on which TextRenderer will execute. | |
31 // | |
32 // |decoder| contains the TextDecoder to use when initializing. | |
acolwell GONE FROM CHROMIUM
2013/10/14 20:42:24
ditto
Matthew Heaney (Chromium)
2013/10/17 05:46:44
Done.
| |
33 // | |
34 // |add_text_track_cb] is called when the demuxer requests that a new | |
35 // text track be created. | |
36 TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | |
37 const AddTextTrackCB& add_text_track_cb); | |
38 ~TextRenderer(); | |
39 | |
40 // Initialize the TextRenderer with the text streams from |demuxer|. | |
acolwell GONE FROM CHROMIUM
2013/10/14 20:42:24
nit: this comment appears to be out of date.
Matthew Heaney (Chromium)
2013/10/17 05:46:44
Done.
Matthew Heaney (Chromium)
2013/10/17 05:46:44
Done.
| |
41 // |ended_cb| is executed when all of the text tracks have reached | |
42 // end of stream, following a play request. | |
43 void Initialize(const base::Closure& ended_cb); | |
44 | |
45 // Start text track cue decoding and rendering, executing |callback| when | |
46 // playback is underway. | |
47 void Play(const base::Closure& callback); | |
48 | |
49 // Temporarily suspend decoding and rendering, executing |callback| when | |
50 // playback has been suspended. | |
51 void Pause(const base::Closure& callback); | |
52 | |
53 // Discard any text data, executing |callback| when completed. | |
54 void Flush(const base::Closure& callback); | |
55 | |
56 // Stop all operations in preparation for being deleted, executing |callback| | |
57 // when complete. | |
58 void Stop(const base::Closure& callback); | |
59 | |
60 // Add new |text_stream|, having the indicated |kind|, |label|, and | |
61 // |language|, to the text stream collection managed by this text renderer. | |
62 void AddTextStream(DemuxerStream* text_stream, | |
63 TextKind kind, | |
64 const std::string& label, | |
65 const std::string& language); | |
66 | |
67 // Returns true if there are extant text tracks. | |
68 bool HasTracks() const; | |
69 | |
70 private: | |
71 // Callback delivered by the demuxer |text_stream| when | |
72 // a read from the stream completes. | |
73 void BufferReady(DemuxerStream* text_stream, | |
74 DemuxerStream::Status status, | |
75 const scoped_refptr<DecoderBuffer>& input); | |
76 | |
77 // Dispatches the decoded cue delivered on the demuxer's |text_stream|. | |
78 void CueReady(DemuxerStream* text_stream, | |
79 const scoped_refptr<TextCue>& text_cue); | |
80 | |
81 void OnAddTextTrackDone(DemuxerStream* text_stream, | |
82 scoped_ptr<TextTrack> text_track); | |
83 | |
84 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
85 base::WeakPtrFactory<TextRenderer> weak_factory_; | |
86 base::WeakPtr<TextRenderer> weak_this_; | |
87 const AddTextTrackCB add_text_track_cb_; | |
88 | |
89 // Callbacks provided during Initialize(). | |
90 base::Closure ended_cb_; | |
91 | |
92 // Callback provided to Pause(). | |
93 base::Closure pause_cb_; | |
94 | |
95 // Callback provided to Stop(). | |
96 base::Closure stop_cb_; | |
97 | |
98 // Simple state tracking variable. | |
99 enum State { | |
100 kUninitialized, | |
101 kPausePending, | |
102 kPaused, | |
103 kPlaying, | |
104 kEnded, | |
105 kStopPending, | |
106 kStopped | |
107 }; | |
108 State state_; | |
109 | |
110 // To determine read progress. | |
111 enum ReadState { | |
112 kReadIdle, | |
113 kReadPending | |
114 }; | |
115 typedef std::map<DemuxerStream*, ReadState> ReadStateMap; | |
116 ReadStateMap read_state_; | |
117 | |
118 typedef std::map<media::DemuxerStream*, media::TextTrack*> TextTrackMap; | |
119 TextTrackMap text_track_map_; | |
120 | |
121 // Indicates how many read requests are in flight. | |
122 int pending_read_count_; | |
123 | |
124 // Indicates how many text streams have not delivered end-of-stream yet. | |
125 int pending_eos_count_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(TextRenderer); | |
acolwell GONE FROM CHROMIUM
2013/10/14 20:42:24
nit: s/COPY_AND_ASSIGN/IMPLICIT_CONSTRUCTORS/
Matthew Heaney (Chromium)
2013/10/17 05:46:44
Done.
Matthew Heaney (Chromium)
2013/10/17 05:46:44
Done.
| |
128 }; | |
129 | |
130 } // namespace media | |
131 | |
132 #endif // MEDIA_BASE_TEXT_RENDERER_H_ | |
OLD | NEW |