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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
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..9c5dcf34fc77e63467e0be53335a7ecf23a84ff4
--- /dev/null
+++ b/media/base/text_renderer.h
@@ -0,0 +1,130 @@
+// 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;
+
+// Receives the decoded cues from the upstream decoder, and passes them
+// onto the TextTrack object associated with each demuxer text stream.
+class MEDIA_EXPORT TextRenderer {
+ public:
+ // |message_loop| is the thread on which TextRenderer will execute.
+ //
+ // |decoder| contains the TextDecoder to use when initializing.
+ //
+ // |add_text_track_cb] is called when the demuxer requests that a new
+ // text track be created.
+ TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop,
+ scoped_ptr<TextDecoder> decoder,
+ const AddTextTrackCB2& add_text_track_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 new |text_stream|, having the indicated |kind|, |label|, and
+ // |language|, to the text stream collection managed by this text renderer.
+ void AddTextStream(DemuxerStream* text_stream,
+ TextKind kind,
+ const std::string& label,
+ const std::string& language);
+
+ // Returns true if there are extant text tracks.
+ bool HasTracks() const;
+
+ 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);
+
+ void OnAddTextTrackDone(DemuxerStream* text_stream,
+ scoped_ptr<TextTrack> text_track);
+
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ base::WeakPtrFactory<TextRenderer> weak_factory_;
+ base::WeakPtr<TextRenderer> weak_this_;
+ scoped_ptr<TextDecoder> decoder_;
+ const AddTextTrackCB2 add_text_track_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_;
+
+ typedef std::map<media::DemuxerStream*, media::TextTrack*> TextTrackMap;
+ TextTrackMap text_track_map_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698