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

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

Powered by Google App Engine
This is Rietveld 408576698