Index: media/base/text_renderer.h |
diff --git a/media/base/text_renderer.h b/media/base/text_renderer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c123bba842532de8c650e225905d1545158981ce |
--- /dev/null |
+++ b/media/base/text_renderer.h |
@@ -0,0 +1,134 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_TEXT_RENDERER_H_ |
+#define MEDIA_BASE_TEXT_RENDERER_H_ |
+ |
+#include <map> |
+ |
+#include "base/callback.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "media/base/media_export.h" |
+#include "media/base/pipeline_status.h" |
+#include "media/base/text_track.h" |
+ |
+namespace base { |
+class MessageLoopProxy; |
+} |
+ |
+namespace media { |
+ |
+class DemuxerStream; |
+class TextCue; |
+class TextDecoder; |
+ |
+// Indicate to the player that an inband text track has been detected in |
+// the media. |
+typedef base::Callback<void(DemuxerStream* text_stream, |
+ TextKind kind, |
+ const std::string& label, |
+ const std::string& language)> AddTextStreamCB; |
+ |
+// Indicates that a cue has been delivered from |text_stream|, and |
+// hence that it should be added to the cue list for its text track. |
+typedef base::Callback<void(DemuxerStream* text_stream, |
+ const scoped_refptr<TextCue>&)> CueReadyCB; |
+ |
+// Receives the decoded cues from the upstream decoder and passes them |
+// up to the player (via CueReadyCB) as they arrive. |
+class MEDIA_EXPORT TextRenderer { |
+ public: |
+ // |message_loop| is the thread on which TextRenderer will execute. |
+ // |
+ // |decoder| contains the TextDecoder to use when initializing. |
+ // |
+ // |cue_ready_cb] is called when the read of a decoded cue completes. |
+ TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
+ scoped_ptr<TextDecoder> decoder, |
+ const AddTextStreamCB& add_text_stream_cb, |
+ const CueReadyCB& cue_ready_cb); |
+ ~TextRenderer(); |
+ |
+ // Initialize the TextRenderer with the text streams from |demuxer|. |
+ // |ended_cb| is executed when all of the text tracks have reached |
+ // end of stream, following a play request. |
+ void Initialize(const base::Closure& ended_cb); |
+ |
+ // Start text track cue decoding and rendering, executing |callback| when |
+ // playback is underway. |
+ void Play(const base::Closure& callback); |
+ |
+ // Temporarily suspend decoding and rendering, executing |callback| when |
+ // playback has been suspended. |
+ void Pause(const base::Closure& callback); |
+ |
+ // Discard any text data, executing |callback| when completed. |
+ void Flush(const base::Closure& callback); |
+ |
+ // Stop all operations in preparation for being deleted, executing |callback| |
+ // when complete. |
+ void Stop(const base::Closure& callback); |
+ |
+ // Add |text_stream| to the text stream collection managed by this text |
+ // renderer, and associate it with |text_track|. |
+ void AddTextStream(DemuxerStream* text_stream, |
+ TextKind kind, |
+ const std::string& label, |
+ const std::string& language); |
+ |
+ private: |
+ // Callback delivered by the text decoder, when the read on the |
+ // demuxer's |text_stream| has completed, and the frame decoded. |
+ void CueReady(DemuxerStream* text_stream, |
+ const scoped_refptr<TextCue>& text_cue); |
+ |
+ scoped_refptr<base::MessageLoopProxy> message_loop_; |
+ base::WeakPtrFactory<TextRenderer> weak_factory_; |
+ base::WeakPtr<TextRenderer> weak_this_; |
+ scoped_ptr<TextDecoder> decoder_; |
+ const AddTextStreamCB add_text_stream_cb_; |
+ const CueReadyCB cue_ready_cb_; |
+ |
+ // Callbacks provided during Initialize(). |
+ base::Closure ended_cb_; |
+ |
+ // Callback provided to Pause(). |
+ base::Closure pause_cb_; |
+ |
+ // Callback provided to Stop(). |
+ base::Closure stop_cb_; |
+ |
+ // Simple state tracking variable. |
+ enum State { |
+ kUninitialized, |
+ kPausePending, |
+ kPaused, |
+ kPlaying, |
+ kEnded, |
+ kStopPending, |
+ kStopped |
+ }; |
+ State state_; |
+ |
+ // To determine read progress. |
+ enum ReadState { |
+ kReadIdle, |
+ kReadPending |
+ }; |
+ typedef std::map<DemuxerStream*, ReadState> ReadStateMap; |
+ ReadStateMap read_state_; |
+ |
+ // Indicates how many read requests are in flight. |
+ int pending_read_count_; |
+ |
+ // Indicates how many text streams have not delivered end-of-stream yet. |
+ int pending_eos_count_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TextRenderer); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_TEXT_RENDERER_H_ |