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/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 // Indicate to the player that an inband text track has been detected in |
| 28 // the media. |
| 29 typedef base::Callback<void(DemuxerStream* text_stream, |
| 30 TextKind kind, |
| 31 const std::string& label, |
| 32 const std::string& language)> AddTextStreamCB; |
| 33 |
| 34 // Indicates that a cue has been delivered from |text_stream|, and |
| 35 // hence that it should be added to the cue list for its text track. |
| 36 typedef base::Callback<void(DemuxerStream* text_stream, |
| 37 const scoped_refptr<TextCue>&)> CueReadyCB; |
| 38 |
| 39 // Receives the decoded cues from the upstream decoder and passes them |
| 40 // up to the player (via CueReadyCB) as they arrive. |
| 41 class MEDIA_EXPORT TextRenderer { |
| 42 public: |
| 43 // |message_loop| is the thread on which TextRenderer will execute. |
| 44 // |
| 45 // |decoder| contains the TextDecoder to use when initializing. |
| 46 // |
| 47 // |cue_ready_cb] is called when the read of a decoded cue completes. |
| 48 TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 49 scoped_ptr<TextDecoder> decoder, |
| 50 const AddTextStreamCB& add_text_stream_cb, |
| 51 const CueReadyCB& cue_ready_cb); |
| 52 ~TextRenderer(); |
| 53 |
| 54 // Initialize the TextRenderer with the text streams from |demuxer|. |
| 55 // |ended_cb| is executed when all of the text tracks have reached |
| 56 // end of stream, following a play request. |
| 57 void Initialize(const base::Closure& ended_cb); |
| 58 |
| 59 // Start text track cue decoding and rendering, executing |callback| when |
| 60 // playback is underway. |
| 61 void Play(const base::Closure& callback); |
| 62 |
| 63 // Temporarily suspend decoding and rendering, executing |callback| when |
| 64 // playback has been suspended. |
| 65 void Pause(const base::Closure& callback); |
| 66 |
| 67 // Discard any text data, executing |callback| when completed. |
| 68 void Flush(const base::Closure& callback); |
| 69 |
| 70 // Stop all operations in preparation for being deleted, executing |callback| |
| 71 // when complete. |
| 72 void Stop(const base::Closure& callback); |
| 73 |
| 74 // Add |text_stream| to the text stream collection managed by this text |
| 75 // renderer, and associate it with |text_track|. |
| 76 void AddTextStream(DemuxerStream* text_stream, |
| 77 TextKind kind, |
| 78 const std::string& label, |
| 79 const std::string& language); |
| 80 |
| 81 private: |
| 82 // Callback delivered by the text decoder, when the read on the |
| 83 // demuxer's |text_stream| has completed, and the frame decoded. |
| 84 void CueReady(DemuxerStream* text_stream, |
| 85 const scoped_refptr<TextCue>& text_cue); |
| 86 |
| 87 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 88 base::WeakPtrFactory<TextRenderer> weak_factory_; |
| 89 base::WeakPtr<TextRenderer> weak_this_; |
| 90 scoped_ptr<TextDecoder> decoder_; |
| 91 const AddTextStreamCB add_text_stream_cb_; |
| 92 const CueReadyCB cue_ready_cb_; |
| 93 |
| 94 // Callbacks provided during Initialize(). |
| 95 base::Closure ended_cb_; |
| 96 |
| 97 // Callback provided to Pause(). |
| 98 base::Closure pause_cb_; |
| 99 |
| 100 // Callback provided to Stop(). |
| 101 base::Closure stop_cb_; |
| 102 |
| 103 // Simple state tracking variable. |
| 104 enum State { |
| 105 kUninitialized, |
| 106 kPausePending, |
| 107 kPaused, |
| 108 kPlaying, |
| 109 kEnded, |
| 110 kStopPending, |
| 111 kStopped |
| 112 }; |
| 113 State state_; |
| 114 |
| 115 // To determine read progress. |
| 116 enum ReadState { |
| 117 kReadIdle, |
| 118 kReadPending |
| 119 }; |
| 120 typedef std::map<DemuxerStream*, ReadState> ReadStateMap; |
| 121 ReadStateMap read_state_; |
| 122 |
| 123 // Indicates how many read requests are in flight. |
| 124 int pending_read_count_; |
| 125 |
| 126 // Indicates how many text streams have not delivered end-of-stream yet. |
| 127 int pending_eos_count_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(TextRenderer); |
| 130 }; |
| 131 |
| 132 } // namespace media |
| 133 |
| 134 #endif // MEDIA_BASE_TEXT_RENDERER_H_ |
OLD | NEW |