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

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/12) 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 struct TextTrackState {
73 // To determine read progress.
74 enum ReadState {
75 kReadIdle,
76 kReadPending
77 };
78
79 explicit TextTrackState(scoped_ptr<TextTrack> text_track);
80
81 ReadState read_state;
82 scoped_ptr<TextTrack> text_track;
83 };
84
85 // Callback delivered by the demuxer |text_stream| when
86 // a read from the stream completes.
87 void BufferReady(DemuxerStream* text_stream,
88 DemuxerStream::Status status,
89 const scoped_refptr<DecoderBuffer>& input);
90
91 // Dispatches the decoded cue delivered on the demuxer's |text_stream|.
92 void CueReady(DemuxerStream* text_stream,
93 const scoped_refptr<TextCue>& text_cue);
94
95 // Dispatched when the AddTextTrackCB completes, after having created
96 // the TextTrack object associated with |text_stream|.
97 void OnAddTextTrackDone(DemuxerStream* text_stream,
98 scoped_ptr<TextTrack> text_track);
99
100 // Utility function to post a read request on |text_stream|.
101 void Read(TextTrackState* state, DemuxerStream* text_stream);
102
103 scoped_refptr<base::MessageLoopProxy> message_loop_;
104 base::WeakPtrFactory<TextRenderer> weak_factory_;
105 base::WeakPtr<TextRenderer> weak_this_;
106 const AddTextTrackCB add_text_track_cb_;
107
108 // Callbacks provided during Initialize().
109 base::Closure ended_cb_;
110
111 // Callback provided to Pause().
112 base::Closure pause_cb_;
113
114 // Callback provided to Stop().
115 base::Closure stop_cb_;
116
117 // Simple state tracking variable.
118 enum State {
119 kUninitialized,
120 kPausePending,
121 kPaused,
122 kPlaying,
123 kEnded,
124 kStopPending,
125 kStopped
126 };
127 State state_;
128
129 typedef std::map<DemuxerStream*, TextTrackState*> TextTrackStateMap;
130 TextTrackStateMap text_track_state_map_;
131
132 // Indicates how many read requests are in flight.
133 int pending_read_count_;
134
135 // Indicates which text streams have not delivered end-of-stream yet.
136 typedef std::set<DemuxerStream*> PendingEosSet;
137 PendingEosSet pending_eos_set_;
138
139 DISALLOW_IMPLICIT_CONSTRUCTORS(TextRenderer);
140 };
141
142 } // namespace media
143
144 #endif // MEDIA_BASE_TEXT_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698