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

Side by Side Diff: media/base/text_renderer.h

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 (11/04) Created 7 years, 1 month 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 #ifndef MEDIA_BASE_TEXT_RENDERER_H_
6 #define MEDIA_BASE_TEXT_RENDERER_H_
7
8 #include <map>
9 #include <set>
10
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_export.h"
16 #include "media/base/pipeline_status.h"
17 #include "media/base/text_track.h"
18
19 namespace base {
20 class MessageLoopProxy;
21 }
22
23 namespace media {
24
25 class TextCue;
26 class TextTrackConfig;
27
28 // Receives decoder buffers from the upstream demuxer, decodes them to text
29 // cues, and then passes them onto the TextTrack object associated with each
30 // demuxer text stream.
31 class MEDIA_EXPORT TextRenderer {
32 public:
33 // |message_loop| is the thread on which TextRenderer will execute.
34 //
35 // |add_text_track_cb] is called when the demuxer requests (via its host)
36 // that a new text track be created.
37 TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop,
38 const AddTextTrackCB& add_text_track_cb);
39 ~TextRenderer();
40
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 |config|, to the text stream
61 // collection managed by this text renderer.
62 void AddTextStream(DemuxerStream* text_stream,
63 const TextTrackConfig& config);
64
65 // Remove |text_stream| from the text stream collection.
66 void RemoveTextStream(DemuxerStream* text_stream);
67
68 // Returns true if there are extant text tracks.
69 bool HasTracks() const;
70
71 private:
72 // Callback delivered by the demuxer |text_stream| when
73 // a read from the stream completes.
74 void BufferReady(DemuxerStream* text_stream,
75 DemuxerStream::Status status,
76 const scoped_refptr<DecoderBuffer>& input);
77
78 // Dispatches the decoded cue delivered on the demuxer's |text_stream|.
79 void CueReady(DemuxerStream* text_stream,
80 const scoped_refptr<TextCue>& text_cue);
81
82 // Dispatched when the AddTextTrackCB completes, after having created
83 // the TextTrack object associated with |text_stream|.
84 void OnAddTextTrackDone(DemuxerStream* text_stream,
85 scoped_ptr<TextTrack> text_track);
86
87 // Utility function to post a read request on |text_stream|.
88 struct TextTrackState;
acolwell GONE FROM CHROMIUM 2013/11/10 19:48:08 nit: Move the actual TextTrackState declaration ri
Matthew Heaney (Chromium) 2013/11/13 05:44:49 Done.
89 void Read(TextTrackState* state, DemuxerStream* text_stream);
90
91 scoped_refptr<base::MessageLoopProxy> message_loop_;
92 base::WeakPtrFactory<TextRenderer> weak_factory_;
93 base::WeakPtr<TextRenderer> weak_this_;
94 const AddTextTrackCB add_text_track_cb_;
95
96 // Callbacks provided during Initialize().
97 base::Closure ended_cb_;
98
99 // Callback provided to Pause().
100 base::Closure pause_cb_;
101
102 // Callback provided to Stop().
103 base::Closure stop_cb_;
104
105 // Simple state tracking variable.
106 enum State {
107 kUninitialized,
108 kPausePending,
109 kPaused,
110 kPlaying,
111 kEnded,
112 kStopPending,
113 kStopped
114 };
115 State state_;
116
117 struct TextTrackState {
118 // To determine read progress.
119 enum ReadState {
120 kReadIdle,
121 kReadPending
122 };
123
124 explicit TextTrackState(scoped_ptr<TextTrack> text_track);
125
126 ReadState read_state;
127 scoped_ptr<TextTrack> text_track;
128 };
129
130 typedef std::map<DemuxerStream*, TextTrackState*> TextTrackStateMap;
131 TextTrackStateMap text_track_state_map_;
132
133 // Indicates how many read requests are in flight.
134 int pending_read_count_;
135
136 // Indicates which text streams have not delivered end-of-stream yet.
137 typedef std::set<DemuxerStream*> PendingEosSet;
138 PendingEosSet pending_eos_set_;
139
140 DISALLOW_IMPLICIT_CONSTRUCTORS(TextRenderer);
141 };
142
143 } // namespace media
144
145 #endif // MEDIA_BASE_TEXT_RENDERER_H_
OLDNEW
« no previous file with comments | « media/base/text_cue.cc ('k') | media/base/text_renderer.cc » ('j') | media/base/text_renderer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698