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

Unified Diff: media/filters/text_renderer_impl.h

Issue 23702007: Render inband text tracks in the media pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 4 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/filters/text_renderer_impl.h
diff --git a/media/filters/text_renderer_impl.h b/media/filters/text_renderer_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..e0204266f936f54427ab878434a085795d1abf7f
--- /dev/null
+++ b/media/filters/text_renderer_impl.h
@@ -0,0 +1,111 @@
+// 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_FILTERS_TEXT_RENDERER_IMPL_H_
+#define MEDIA_FILTERS_TEXT_RENDERER_IMPL_H_
+
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "media/base/media_export.h"
+#include "media/base/text_renderer.h"
+
+namespace base {
+class MessageLoopProxy;
+}
+
+namespace media {
+
+class TextBuffer;
+class TextDecoder;
+
+// Indicates that a cue has been delivered from the stream at |index|,
+// and hence that it should be added to the cue list for its text track.
+typedef base::Callback<void(int index,
+ const scoped_refptr<TextBuffer>&)> CueReadyCB;
+
+// Receives the decoded cues from the upstream decoder and passes them
+// up to the player (via CueReadyCB) as they arrive.
+class MEDIA_EXPORT TextRendererImpl : public TextRenderer {
+ public:
+ // |message_loop| is the thread on which TextRendererImpl will execute.
+ //
+ // |decoder| contains the TextDecoder to use when initializing.
+ //
+ // |cue_ready_cb] is called when the read of a decoded cue completes.
+ TextRendererImpl(const scoped_refptr<base::MessageLoopProxy>& message_loop,
+ scoped_ptr<TextDecoder> decoder,
+ const CueReadyCB& cue_ready_cb);
+ virtual ~TextRendererImpl();
+
+ // TextRenderer implementation.
+ virtual void Initialize(Demuxer* demuxer,
acolwell GONE FROM CHROMIUM 2013/09/12 00:15:15 I think there should be an AddStream(DemuxerStream
Matthew Heaney (Chromium) 2013/09/13 19:51:54 OK. I had written you a few questions about the e
Matthew Heaney (Chromium) 2013/09/20 23:53:54 I added the new method(s) to DemuxerHost and Pipel
+ const PipelineStatusCB& init_cb,
+ const base::Closure& ended_cb) OVERRIDE;
+ virtual void Play(const base::Closure& callback) OVERRIDE;
+ virtual void Pause(const base::Closure& callback) OVERRIDE;
+ virtual void Stop(const base::Closure& callback) OVERRIDE;
+
acolwell GONE FROM CHROMIUM 2013/09/12 00:15:15 I think there should be an AddTrack() / RemoveTrac
Matthew Heaney (Chromium) 2013/09/13 19:51:54 OK, I'll look into that.
+ private:
+ // Callback delivered by the text decoder, when the read on the text
+ // demuxer stream at |index| has completed, and the frame decoded.
+ void CueReady(int index, const scoped_refptr<TextBuffer>& text_buffer);
+
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ base::WeakPtrFactory<TextRendererImpl> weak_factory_;
+ base::WeakPtr<TextRendererImpl> weak_this_;
+ scoped_ptr<TextDecoder> decoder_;
+ const CueReadyCB cue_ready_cb_;
+
+ // Callbacks provided during Initialize().
+ PipelineStatusCB init_cb_;
+ base::Closure ended_cb_;
+
+ // Callback provided to Pause().
+ base::Closure pause_cb_;
+
+ // Callback provided to Stop().
+ base::Closure stop_cb_;
+
+ // After Initialize() has completed, all variables below must be accessed
+ // under |lock_|. ------------------------------------------------------------
+ base::Lock lock_;
acolwell GONE FROM CHROMIUM 2013/09/12 00:15:15 Do you really need this lock? Doesn't this code on
Matthew Heaney (Chromium) 2013/09/13 19:51:54 Done.
+
+ // Simple state tracking variable.
+ enum State {
+ kUninitialized,
+ kPausePending,
+ kPaused,
+ kPlaying,
+ kStopPending,
+ kStopped
+ };
+ State state_;
+
+ // To differentiate among demuxer stream kinds, and determine read progress.
+ enum ReadState {
+ kReadInactive,
+ kReadIdle,
+ kReadPending
+ };
+ std::vector<ReadState> read_state_;
+
+ // Indicates how many text streams, among all demuxer streams.
+ int text_stream_count_;
+
+ // Indicates how many read requests are in flight.
+ int pending_read_count_;
+
+ // Indicates how many text streams have delivered end-of-stream indications.
acolwell GONE FROM CHROMIUM 2013/09/12 00:15:15 nit: This comment does not appear to match the cod
Matthew Heaney (Chromium) 2013/09/13 19:51:54 Done.
+ int eos_count_;
+
+ // End variables which must be accessed under |lock_|. ----------------------
+
+ DISALLOW_COPY_AND_ASSIGN(TextRendererImpl);
+};
+
+} // namespace media
+
+#endif // MEDIA_FILTERS_TEXT_RENDERER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698