OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_FRAME_PROCESSOR_H_ | 5 #ifndef MEDIA_FILTERS_FRAME_PROCESSOR_H_ |
6 #define MEDIA_FILTERS_FRAME_PROCESSOR_H_ | 6 #define MEDIA_FILTERS_FRAME_PROCESSOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // false means "segments". | 42 // false means "segments". |
43 // See http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode. | 43 // See http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode. |
44 bool sequence_mode() { return sequence_mode_; } | 44 bool sequence_mode() { return sequence_mode_; } |
45 void SetSequenceMode(bool sequence_mode); | 45 void SetSequenceMode(bool sequence_mode); |
46 | 46 |
47 // Processes buffers in |audio_buffers|, |video_buffers|, and |text_map|. | 47 // Processes buffers in |audio_buffers|, |video_buffers|, and |text_map|. |
48 // Returns true on success or false on failure which indicates decode error. | 48 // Returns true on success or false on failure which indicates decode error. |
49 // |append_window_start| and |append_window_end| correspond to the MSE spec's | 49 // |append_window_start| and |append_window_end| correspond to the MSE spec's |
50 // similarly named source buffer attributes that are used in coded frame | 50 // similarly named source buffer attributes that are used in coded frame |
51 // processing. | 51 // processing. |
| 52 // |*new_media_segment| tracks whether the next buffers processed within the |
| 53 // append window represent the start of a new media segment. This method may |
| 54 // both use and update this flag. |
52 // Uses |*timestamp_offset| according to the coded frame processing algorithm, | 55 // Uses |*timestamp_offset| according to the coded frame processing algorithm, |
53 // including updating it as required in 'sequence' mode frame processing. | 56 // including updating it as required in 'sequence' mode frame processing. |
54 bool ProcessFrames(const StreamParser::BufferQueue& audio_buffers, | 57 bool ProcessFrames(const StreamParser::BufferQueue& audio_buffers, |
55 const StreamParser::BufferQueue& video_buffers, | 58 const StreamParser::BufferQueue& video_buffers, |
56 const StreamParser::TextBufferQueueMap& text_map, | 59 const StreamParser::TextBufferQueueMap& text_map, |
57 base::TimeDelta append_window_start, | 60 base::TimeDelta append_window_start, |
58 base::TimeDelta append_window_end, | 61 base::TimeDelta append_window_end, |
| 62 bool* new_media_segment, |
59 base::TimeDelta* timestamp_offset); | 63 base::TimeDelta* timestamp_offset); |
60 | 64 |
61 // Signals the frame processor to update its group start timestamp to be | 65 // Signals the frame processor to update its group start timestamp to be |
62 // |timestamp_offset| if it is in sequence append mode. | 66 // |timestamp_offset| if it is in sequence append mode. |
63 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); | 67 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); |
64 | 68 |
65 // Adds a new track with unique track ID |id|. | 69 // Adds a new track with unique track ID |id|. |
66 // If |id| has previously been added, returns false to indicate error. | 70 // If |id| has previously been added, returns false to indicate error. |
67 // Otherwise, returns true, indicating future ProcessFrames() will emit | 71 // Otherwise, returns true, indicating future ProcessFrames() will emit |
68 // frames for the track |id| to |stream|. | 72 // frames for the track |id| to |stream|. |
(...skipping 13 matching lines...) Expand all Loading... |
82 // 2-5 of the MSE Reset Parser State algorithm described at | 86 // 2-5 of the MSE Reset Parser State algorithm described at |
83 // http://www.w3.org/TR/media-source/#sourcebuffer-reset-parser-state | 87 // http://www.w3.org/TR/media-source/#sourcebuffer-reset-parser-state |
84 void Reset(); | 88 void Reset(); |
85 | 89 |
86 // Must be called when the audio config is updated. Used to manage when | 90 // Must be called when the audio config is updated. Used to manage when |
87 // the preroll buffer is cleared and the allowed "fudge" factor between | 91 // the preroll buffer is cleared and the allowed "fudge" factor between |
88 // preroll buffers. | 92 // preroll buffers. |
89 void OnPossibleAudioConfigUpdate(const AudioDecoderConfig& config); | 93 void OnPossibleAudioConfigUpdate(const AudioDecoderConfig& config); |
90 | 94 |
91 private: | 95 private: |
92 friend class FrameProcessorTest; | |
93 | |
94 typedef std::map<StreamParser::TrackId, MseTrackBuffer*> TrackBufferMap; | 96 typedef std::map<StreamParser::TrackId, MseTrackBuffer*> TrackBufferMap; |
95 | 97 |
96 // If |track_buffers_| contains |id|, returns a pointer to the associated | 98 // If |track_buffers_| contains |id|, returns a pointer to the associated |
97 // MseTrackBuffer. Otherwise, returns NULL. | 99 // MseTrackBuffer. Otherwise, returns NULL. |
98 MseTrackBuffer* FindTrack(StreamParser::TrackId id); | 100 MseTrackBuffer* FindTrack(StreamParser::TrackId id); |
99 | 101 |
100 // Signals all track buffers' streams that a coded frame group is starting | 102 // Signals all track buffers' streams that a new media segment is starting |
101 // with decode timestamp |start_timestamp|. | 103 // with decode timestamp |segment_timestamp|. |
102 void NotifyStartOfCodedFrameGroup(DecodeTimestamp start_timestamp); | 104 void NotifyNewMediaSegmentStarting(DecodeTimestamp segment_timestamp); |
103 | 105 |
104 // Helper that signals each track buffer to append any processed, but not yet | 106 // Helper that signals each track buffer to append any processed, but not yet |
105 // appended, frames to its stream. Returns true on success, or false if one or | 107 // appended, frames to its stream. Returns true on success, or false if one or |
106 // more of the appends failed. | 108 // more of the appends failed. |
107 bool FlushProcessedFrames(); | 109 bool FlushProcessedFrames(); |
108 | 110 |
109 // Handles partial append window trimming of |buffer|. Returns true if the | 111 // Handles partial append window trimming of |buffer|. Returns true if the |
110 // given |buffer| can be partially trimmed or have preroll added; otherwise, | 112 // given |buffer| can be partially trimmed or have preroll added; otherwise, |
111 // returns false. | 113 // returns false. |
112 // | 114 // |
(...skipping 12 matching lines...) Expand all Loading... |
125 bool HandlePartialAppendWindowTrimming( | 127 bool HandlePartialAppendWindowTrimming( |
126 base::TimeDelta append_window_start, | 128 base::TimeDelta append_window_start, |
127 base::TimeDelta append_window_end, | 129 base::TimeDelta append_window_end, |
128 const scoped_refptr<StreamParserBuffer>& buffer); | 130 const scoped_refptr<StreamParserBuffer>& buffer); |
129 | 131 |
130 // Helper that processes one frame with the coded frame processing algorithm. | 132 // Helper that processes one frame with the coded frame processing algorithm. |
131 // Returns false on error or true on success. | 133 // Returns false on error or true on success. |
132 bool ProcessFrame(const scoped_refptr<StreamParserBuffer>& frame, | 134 bool ProcessFrame(const scoped_refptr<StreamParserBuffer>& frame, |
133 base::TimeDelta append_window_start, | 135 base::TimeDelta append_window_start, |
134 base::TimeDelta append_window_end, | 136 base::TimeDelta append_window_end, |
135 base::TimeDelta* timestamp_offset); | 137 base::TimeDelta* timestamp_offset, |
| 138 bool* new_media_segment); |
136 | 139 |
137 // TrackId-indexed map of each track's stream. | 140 // TrackId-indexed map of each track's stream. |
138 TrackBufferMap track_buffers_; | 141 TrackBufferMap track_buffers_; |
139 | 142 |
140 // The last audio buffer seen by the frame processor that was removed because | 143 // The last audio buffer seen by the frame processor that was removed because |
141 // it was entirely before the start of the append window. | 144 // it was entirely before the start of the append window. |
142 scoped_refptr<StreamParserBuffer> audio_preroll_buffer_; | 145 scoped_refptr<StreamParserBuffer> audio_preroll_buffer_; |
143 | 146 |
144 // The AudioDecoderConfig associated with buffers handed to ProcessFrames(). | 147 // The AudioDecoderConfig associated with buffers handed to ProcessFrames(). |
145 AudioDecoderConfig current_audio_config_; | 148 AudioDecoderConfig current_audio_config_; |
146 base::TimeDelta sample_duration_; | 149 base::TimeDelta sample_duration_; |
147 | 150 |
148 // The AppendMode of the associated SourceBuffer. | 151 // The AppendMode of the associated SourceBuffer. |
149 // See SetSequenceMode() for interpretation of |sequence_mode_|. | 152 // See SetSequenceMode() for interpretation of |sequence_mode_|. |
150 // Per http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode: | 153 // Per http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode: |
151 // Controls how a sequence of media segments are handled. This is initially | 154 // Controls how a sequence of media segments are handled. This is initially |
152 // set to false ("segments"). | 155 // set to false ("segments"). |
153 bool sequence_mode_ = false; | 156 bool sequence_mode_ = false; |
154 | 157 |
155 // Flag to track whether or not the next processed frame is a continuation of | |
156 // a coded frame group. This flag resets to false upon detection of | |
157 // discontinuity, and becomes true once a processed coded frame for the | |
158 // current coded frame group is sent to its track buffer. | |
159 bool in_coded_frame_group_ = false; | |
160 | |
161 // Tracks the MSE coded frame processing variable of same name. | 158 // Tracks the MSE coded frame processing variable of same name. |
162 // Initially kNoTimestamp(), meaning "unset". | 159 // Initially kNoTimestamp(), meaning "unset". |
163 base::TimeDelta group_start_timestamp_; | 160 base::TimeDelta group_start_timestamp_; |
164 | 161 |
165 // Tracks the MSE coded frame processing variable of same name. It stores the | 162 // Tracks the MSE coded frame processing variable of same name. It stores the |
166 // highest coded frame end timestamp across all coded frames in the current | 163 // highest coded frame end timestamp across all coded frames in the current |
167 // coded frame group. It is set to 0 when the SourceBuffer object is created | 164 // coded frame group. It is set to 0 when the SourceBuffer object is created |
168 // and gets updated by ProcessFrames(). | 165 // and gets updated by ProcessFrames(). |
169 base::TimeDelta group_end_timestamp_; | 166 base::TimeDelta group_end_timestamp_; |
170 | 167 |
171 UpdateDurationCB update_duration_cb_; | 168 UpdateDurationCB update_duration_cb_; |
172 | 169 |
173 // MediaLog for reporting messages and properties to debug content and engine. | 170 // MediaLog for reporting messages and properties to debug content and engine. |
174 scoped_refptr<MediaLog> media_log_; | 171 scoped_refptr<MediaLog> media_log_; |
175 | 172 |
176 // Counters that limit spam to |media_log_| for frame processor warnings. | 173 // Counters that limit spam to |media_log_| for frame processor warnings. |
177 int num_dropped_preroll_warnings_ = 0; | 174 int num_dropped_preroll_warnings_ = 0; |
178 int num_dts_beyond_pts_warnings_ = 0; | 175 int num_dts_beyond_pts_warnings_ = 0; |
179 | 176 |
180 DISALLOW_COPY_AND_ASSIGN(FrameProcessor); | 177 DISALLOW_COPY_AND_ASSIGN(FrameProcessor); |
181 }; | 178 }; |
182 | 179 |
183 } // namespace media | 180 } // namespace media |
184 | 181 |
185 #endif // MEDIA_FILTERS_FRAME_PROCESSOR_H_ | 182 #endif // MEDIA_FILTERS_FRAME_PROCESSOR_H_ |
OLD | NEW |