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 decoder buffers from the upstream demuxer, decodes them to text | |
27 // cues, and then passes them onto the TextTrack object associated with each | |
28 // demuxer text stream. | |
29 class MEDIA_EXPORT TextRenderer { | |
30 public: | |
31 // |message_loop| is the thread on which TextRenderer will execute. | |
32 // | |
33 // |add_text_track_cb] is called when the demuxer requests (via its host) | |
34 // that a new text track be created. | |
35 TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | |
36 const AddTextTrackCB& add_text_track_cb); | |
37 ~TextRenderer(); | |
38 | |
39 // |ended_cb| is executed when all of the text tracks have reached | |
40 // end of stream, following a play request. | |
41 void Initialize(const base::Closure& ended_cb); | |
42 | |
43 // Start text track cue decoding and rendering, executing |callback| when | |
44 // playback is underway. | |
45 void Play(const base::Closure& callback); | |
46 | |
47 // Temporarily suspend decoding and rendering, executing |callback| when | |
48 // playback has been suspended. | |
49 void Pause(const base::Closure& callback); | |
50 | |
51 // Discard any text data, executing |callback| when completed. | |
52 void Flush(const base::Closure& callback); | |
53 | |
54 // Stop all operations in preparation for being deleted, executing |callback| | |
55 // when complete. | |
56 void Stop(const base::Closure& callback); | |
57 | |
58 // Add new |text_stream|, having the indicated |kind|, |label|, and | |
acolwell GONE FROM CHROMIUM
2013/10/24 18:57:51
nit: Update comment to refer to |config| instead.
Matthew Heaney (Chromium)
2013/10/25 03:05:38
Done.
| |
59 // |language|, to the text stream collection managed by this text renderer. | |
60 void AddTextStream(DemuxerStream* text_stream, | |
61 const TextTrackConfig& config); | |
62 | |
63 // Remove |text_stream| from the text stream collection. | |
64 void RemoveTextStream(DemuxerStream* text_stream); | |
65 | |
66 // Returns true if there are extant text tracks. | |
67 bool HasTracks() const; | |
68 | |
69 private: | |
70 // Callback delivered by the demuxer |text_stream| when | |
71 // a read from the stream completes. | |
72 void BufferReady(DemuxerStream* text_stream, | |
73 DemuxerStream::Status status, | |
74 const scoped_refptr<DecoderBuffer>& input); | |
75 | |
76 // Dispatches the decoded cue delivered on the demuxer's |text_stream|. | |
77 void CueReady(DemuxerStream* text_stream, | |
78 const scoped_refptr<TextCue>& text_cue); | |
79 | |
80 // Dispatched when the AddTextTrackCB completes, after having created | |
81 // the TextTrack object associated with |text_stream|. | |
82 void OnAddTextTrackDone(DemuxerStream* text_stream, | |
83 scoped_ptr<TextTrack> text_track); | |
84 | |
85 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
86 base::WeakPtrFactory<TextRenderer> weak_factory_; | |
87 base::WeakPtr<TextRenderer> weak_this_; | |
88 const AddTextTrackCB add_text_track_cb_; | |
89 | |
90 // Callbacks provided during Initialize(). | |
91 base::Closure ended_cb_; | |
92 | |
93 // Callback provided to Pause(). | |
94 base::Closure pause_cb_; | |
95 | |
96 // Callback provided to Stop(). | |
97 base::Closure stop_cb_; | |
98 | |
99 // Simple state tracking variable. | |
100 enum State { | |
101 kUninitialized, | |
102 kPausePending, | |
103 kPaused, | |
104 kPlaying, | |
105 kEnded, | |
106 kStopPending, | |
107 kStopped | |
108 }; | |
109 State state_; | |
110 | |
111 // To determine read progress. | |
112 enum ReadState { | |
acolwell GONE FROM CHROMIUM
2013/10/24 18:57:51
nit: Move enum into TextTrackState.
Matthew Heaney (Chromium)
2013/10/25 03:05:38
Done.
| |
113 kReadIdle, | |
114 kReadPending | |
115 }; | |
116 | |
117 struct TextTrackState { | |
118 ReadState read_state; | |
119 media::TextTrack* text_track; | |
acolwell GONE FROM CHROMIUM
2013/10/24 18:57:51
nit: You shouldn't need media:: here.
make this a
Matthew Heaney (Chromium)
2013/10/25 03:05:38
Done.
| |
120 }; | |
121 | |
122 typedef std::map<DemuxerStream*, TextTrackState> TextTrackStateMap; | |
acolwell GONE FROM CHROMIUM
2013/10/24 18:57:51
nit: Make this TextTrackState* so the renderer can
Matthew Heaney (Chromium)
2013/10/25 03:05:38
Done.
| |
123 TextTrackStateMap text_track_state_map_; | |
124 | |
125 // Indicates how many read requests are in flight. | |
126 int pending_read_count_; | |
127 | |
128 // Indicates how many text streams have not delivered end-of-stream yet. | |
129 int pending_eos_count_; | |
130 | |
131 DISALLOW_IMPLICIT_CONSTRUCTORS(TextRenderer); | |
acolwell GONE FROM CHROMIUM
2013/10/24 18:57:51
nit: fix indent.
Matthew Heaney (Chromium)
2013/10/25 03:05:38
Done.
| |
132 }; | |
133 | |
134 } // namespace media | |
135 | |
136 #endif // MEDIA_BASE_TEXT_RENDERER_H_ | |
OLD | NEW |