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 // Establish representation invariants for the TextRenderer. | |
acolwell GONE FROM CHROMIUM
2013/10/21 20:10:40
nit: Remove this comment since it seems unnecessar
Matthew Heaney (Chromium)
2013/10/23 05:09:01
Done.
| |
40 // |ended_cb| is executed when all of the text tracks have reached | |
41 // end of stream, following a play request. | |
42 void Initialize(const base::Closure& ended_cb); | |
43 | |
44 // Start text track cue decoding and rendering, executing |callback| when | |
45 // playback is underway. | |
46 void Play(const base::Closure& callback); | |
47 | |
48 // Temporarily suspend decoding and rendering, executing |callback| when | |
49 // playback has been suspended. | |
50 void Pause(const base::Closure& callback); | |
51 | |
52 // Discard any text data, executing |callback| when completed. | |
53 void Flush(const base::Closure& callback); | |
54 | |
55 // Stop all operations in preparation for being deleted, executing |callback| | |
56 // when complete. | |
57 void Stop(const base::Closure& callback); | |
58 | |
59 // Add new |text_stream|, having the indicated |kind|, |label|, and | |
60 // |language|, to the text stream collection managed by this text renderer. | |
61 void AddTextStream(DemuxerStream* text_stream, | |
62 TextKind kind, | |
acolwell GONE FROM CHROMIUM
2013/10/21 20:10:40
nit: Use const TextTrackConfig& here.
Matthew Heaney (Chromium)
2013/10/23 05:09:01
Done.
| |
63 const std::string& label, | |
64 const std::string& language); | |
65 | |
66 // Remove |text_stream| from the text stream collection. | |
67 void RemoveTextStream(DemuxerStream* text_stream); | |
68 | |
69 // Returns true if there are extant text tracks. | |
70 bool HasTracks() const; | |
71 | |
72 private: | |
73 // Callback delivered by the demuxer |text_stream| when | |
74 // a read from the stream completes. | |
75 void BufferReady(DemuxerStream* text_stream, | |
76 DemuxerStream::Status status, | |
77 const scoped_refptr<DecoderBuffer>& input); | |
78 | |
79 // Dispatches the decoded cue delivered on the demuxer's |text_stream|. | |
80 void CueReady(DemuxerStream* text_stream, | |
81 const scoped_refptr<TextCue>& text_cue); | |
82 | |
83 // Dispatched when the AddTextTrackCB completes, after having created | |
84 // the TextTrack object associated with |text_stream|. | |
85 void OnAddTextTrackDone(DemuxerStream* text_stream, | |
86 scoped_ptr<TextTrack> text_track); | |
87 | |
88 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
89 base::WeakPtrFactory<TextRenderer> weak_factory_; | |
90 base::WeakPtr<TextRenderer> weak_this_; | |
91 const AddTextTrackCB add_text_track_cb_; | |
92 | |
93 // Callbacks provided during Initialize(). | |
94 base::Closure ended_cb_; | |
95 | |
96 // Callback provided to Pause(). | |
97 base::Closure pause_cb_; | |
98 | |
99 // Callback provided to Stop(). | |
100 base::Closure stop_cb_; | |
101 | |
102 // Simple state tracking variable. | |
103 enum State { | |
104 kUninitialized, | |
105 kPausePending, | |
106 kPaused, | |
107 kPlaying, | |
108 kEnded, | |
109 kStopPending, | |
110 kStopped | |
111 }; | |
112 State state_; | |
113 | |
114 // To determine read progress. | |
115 enum ReadState { | |
116 kReadIdle, | |
117 kReadPending | |
118 }; | |
119 typedef std::map<DemuxerStream*, ReadState> ReadStateMap; | |
120 ReadStateMap read_state_; | |
121 | |
122 typedef std::map<media::DemuxerStream*, media::TextTrack*> TextTrackMap; | |
123 TextTrackMap text_track_map_; | |
acolwell GONE FROM CHROMIUM
2013/10/21 20:10:40
nit: Create a TextTrackState object that holds the
Matthew Heaney (Chromium)
2013/10/23 05:09:01
Done.
| |
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); | |
132 }; | |
133 | |
134 } // namespace media | |
135 | |
136 #endif // MEDIA_BASE_TEXT_RENDERER_H_ | |
OLD | NEW |