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