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

Unified Diff: media/filters/frame_processor_base.h

Issue 191513002: Extract coded frame processing from SourceState into LegacyFrameProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix some lint errors Created 6 years, 9 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/frame_processor_base.h
diff --git a/media/filters/frame_processor_base.h b/media/filters/frame_processor_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..fd6b39802c41a84b9f2dfd9471c4cf1047a7333d
--- /dev/null
+++ b/media/filters/frame_processor_base.h
@@ -0,0 +1,178 @@
+// Copyright 2014 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_FRAME_PROCESSOR_BASE_H_
+#define MEDIA_FILTERS_FRAME_PROCESSOR_BASE_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/time/time.h"
+#include "media/base/media_export.h"
+#include "media/base/stream_parser.h"
+#include "media/filters/chunk_demuxer.h"
+
+namespace media {
+
+// Helper class to capture per-track details needed by a frame processor. Some
+// of this information may be duplicated in the short-term in the associated
+// ChunkDemuxerStream and SourceBufferStream for a track.
+// This parallels the MSE spec each of a SourceBuffer's Track Buffers at
+// http://www.w3.org/TR/media-source/#track-buffers.
+class TrackBufferAppendState {
acolwell GONE FROM CHROMIUM 2014/03/08 21:15:51 nit: How about we just call this MseTrackBuffer?
wolenetz 2014/03/10 23:03:47 Done.
+ public:
+ explicit TrackBufferAppendState(ChunkDemuxerStream* stream);
+ ~TrackBufferAppendState();
+ // Get/set |needs_random_access_point_|.
+ bool needs_random_access_point() const {
+ return needs_random_access_point_;
+ }
+ void set_needs_random_access_point(bool needs_random_access_point) {
+ needs_random_access_point_ = needs_random_access_point;
+ }
+ // Gets a pointer to this track's ChunkDemuxerStream.
+ ChunkDemuxerStream* stream() const { return stream_; }
+ // Sets |needs_random_access_point_| to true.
+ // TODO(wolenetz): Add the rest of the new coded frame processing algorithm
+ // track buffer attributes and reset them here. See http://crbug.com/249422.
+ void Reset();
+
+ private:
+ // Keeps track of whether the track buffer is waiting for a random access
+ // point coded frame. Initially set to true to indicate that a random access
+ // point coded frame is needed before anything can be added to the track
+ // buffer.
+ bool needs_random_access_point_;
+ // Pointer to the stream associated with this track. The stream is not owned
+ // by |this|.
+ ChunkDemuxerStream* const stream_;
+ DISALLOW_COPY_AND_ASSIGN(TrackBufferAppendState);
+};
+
+// Abstract interface for helper class implementation of Media Source
+// Extension's coded frame processing algorithm.
+// TODO(wolenetz): Once the new FrameProcessor implementation stabilizes, remove
+// LegacyFrameProcessor and fold this interface into FrameProcessor. See
+// http://crbug.com/249422.
+class MEDIA_EXPORT FrameProcessorBase {
+ public:
+ // TODO(wolenetz/acolwell): Ensure that all TrackIds are coherent and unique
+ // for each track buffer. For now, special track identifiers are used for each
+ // of audio and video here, and text TrackIds are assumed to be non-negative.
+ // See http://crbug.com/341581.
+ enum {
+ kAudioTrackId = -2,
+ kVideoTrackId = -3
+ };
+
+ // Callback signature used to notify ChunkDemuxer of timestamps that may cause
+ // the duration to be updated.
+ typedef base::Callback<void(
+ base::TimeDelta, ChunkDemuxerStream*)> IncreaseDurationCB;
+
+ virtual ~FrameProcessorBase();
+
+ // Get/set the current append mode. Before setting, caller must do steps 1-6
acolwell GONE FROM CHROMIUM 2014/03/08 21:15:51 This comment seems overly verbose. I think simply
wolenetz 2014/03/10 23:03:47 Done.
+ // of http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode. This setter
+ // implements steps 7-8.
+ // Note, callers may cache the last successfully set append mode since the
+ // coded frame processing algorithm implemented here does not initiate changes
+ // to the append mode.
+ //
+ // If |sequence_mode| is false, sets the current append mode to "segments":
+ // Per http://www.w3.org/TR/media-source/#idl-def-AppendMode.segments:
+ // The timestamps in the media segment determine where the coded frames are
+ // placed in the presentation. Media segments can be appended in any order.
+ //
+ // If |sequence_mode| is true, sets the current append mode to "sequence":
+ // Per http://www.w3.org/TR/media-source/#idl-def-AppendMode.sequence:
+ // Media segments will be treated as adjacent in time independent of the
+ // timestamps in the media segment. Coded frames in a new media segment will
+ // be placed immediately after the coded frames in the previous media segment.
+ // timestamp_offset() will be updated if a new offset is needed to make the
+ // new media segments adjacent to the previous media segment.
+ // SetTimestampOffset() while in "sequence" mode allows a media segment to be
+ // placed at a specific position in the timeline without any knowledge of the
+ // timestamps in the media segment.
+ // TODO(wolenetz): Actually implement "sequence" mode compliant coded frame
+ // processing in a new subclass. See http://crbug.com/249422.
+ bool sequence_mode() { return sequence_mode_; }
+ virtual void SetSequenceMode(bool sequence_mode) = 0;
+
+ // Sets the value of |timestamp_offset_|.
+ // Per http://www.w3.org/TR/media-source/#widl-SourceBuffer-timestampOffset:
+ // Controls the offset applied to timestamps inside subsequence media segments
+ // that are appended to the assocated SourceBuffer. It is initially set to 0
+ // which indicates that no offset is being applied.
+ // Before setting, caller must do steps 1-5. This setter implements steps 6-7.
+ virtual void SetTimestampOffset(const base::TimeDelta& timestamp_offset) = 0;
acolwell GONE FROM CHROMIUM 2014/03/08 21:15:51 I think this should be removed and the value passe
wolenetz 2014/03/10 23:03:47 Done.
+
+ // Merges the input queues, assumed to be internally in decode timestamp
+ // order, and then processes them. Returns true on success or false on failure
+ // which indicates decode error.
+ // |*new_media_segment| tracks whether the next buffers processed within the
+ // append window represent the start of a new media segment. This method may
+ // both use and update this flag.
+ // If |timestamp_offset| is not NULL, and if the frame processing updates
+ // |timestamp_offset_|, then |*timestamp_offset| is also updated.
+ virtual bool MergeQueuesAndProcessFrames(
+ const StreamParser::BufferQueue& audio_buffers,
+ const StreamParser::BufferQueue& video_buffers,
+ const StreamParser::TextBufferQueueMap& text_map,
+ bool* new_media_segment,
+ double* timestamp_offset) = 0;
+
+ void set_append_window_start(base::TimeDelta start) {
+ append_window_start_ = start;
+ }
+
+ void set_append_window_end(base::TimeDelta end) {
+ append_window_end_ = end;
+ }
+
+ // Adds a new track with unique track ID |id|.
+ // If |id| has previously been added, returns false to indicate error.
+ // Otherwise, returns true, indicating future ProcessFrames() will emit
+ // frames for the track |id| to |stream|.
+ bool AddTrack(StreamParser::TrackId id, ChunkDemuxerStream* stream);
+
+ // Resets state for the coded frame processing algorithm as described in steps
+ // 2-5 of the MSE Reset Parser State algorithm described at
+ // http://www.w3.org/TR/media-source/#sourcebuffer-reset-parser-state
+ void Reset();
+
+ protected:
+ typedef std::map<StreamParser::TrackId, TrackBufferAppendState*> TrackMap;
acolwell GONE FROM CHROMIUM 2014/03/08 21:15:51 nit: s/TrackMap/TrackBufferMap/?
wolenetz 2014/03/10 23:03:47 Done.
+
+ explicit FrameProcessorBase(const IncreaseDurationCB& increase_duration_cb);
+
+ // If |tracks_| contains |id|, returns a pointer to the associated
+ // TrackBufferAppendState. Otherwise, returns NULL.
+ TrackBufferAppendState* FindTrack(StreamParser::TrackId id);
+
+ // The AppendMode of the associated SourceBuffer.
+ // See SetSequenceMode() for interpretation of |sequence_mode_|.
+ // Per http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode:
+ // Controls how a sequence of media segments are handled. This is initially
+ // set to false ("segments").
+ bool sequence_mode_;
+
+ // See SetTimestampOffset() for interpretation of this value.
+ // TODO(wolenetz): Rework so |timestamp_offset_| is only valid during
+ // actual frame processing, and otherwise is owned by caller. See
+ // http://crbug.com/347623.
+ base::TimeDelta timestamp_offset_;
+
+ base::TimeDelta append_window_start_;
+ base::TimeDelta append_window_end_;
+
+ IncreaseDurationCB increase_duration_cb_;
+
+ // TrackId-indexed map of each track's stream.
+ TrackMap tracks_;
acolwell GONE FROM CHROMIUM 2014/03/08 21:15:51 nit: s/tracks_/track_buffers_/ just so the code wi
wolenetz 2014/03/10 23:03:47 Done.
+};
+
+} // namespace media
+
+#endif // MEDIA_FILTERS_FRAME_PROCESSOR_BASE_H_

Powered by Google App Engine
This is Rietveld 408576698