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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_LEGACY_FRAME_PROCESSOR_H_
6 #define MEDIA_FILTERS_LEGACY_FRAME_PROCESSOR_H_
8 #include "base/basictypes.h"
9 #include "base/time/time.h"
10 #include "media/base/media_export.h"
11 #include "media/base/stream_parser.h"
12 #include "media/filters/frame_processor_base.h"
16 // Helper class that implements Media Source Extension's coded frame processing
18 class MEDIA_EXPORT LegacyFrameProcessor : public FrameProcessorBase {
20 // Callback signature used to notify ChunkDemuxer of an end timestamp that may
21 // cause the duration to be updated.
22 typedef base::Callback<void(base::TimeDelta)> IncreaseDurationCB;
24 explicit LegacyFrameProcessor(const IncreaseDurationCB& increase_duration_cb);
25 virtual ~LegacyFrameProcessor();
27 // FrameProcessorBase implementation
28 virtual void SetSequenceMode(bool sequence_mode) OVERRIDE;
29 virtual bool ProcessFrames(const StreamParser::BufferQueue& audio_buffers,
30 const StreamParser::BufferQueue& video_buffers,
31 const StreamParser::TextBufferQueueMap& text_map,
32 base::TimeDelta append_window_start,
33 base::TimeDelta append_window_end,
34 bool* new_media_segment,
35 base::TimeDelta* timestamp_offset) OVERRIDE;
38 // Helper function that adds |timestamp_offset| to each buffer in |buffers|.
39 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers,
40 base::TimeDelta timestamp_offset);
42 // Filters out buffers that are outside of the append window
43 // [|append_window_start|, |append_window_end|). |track|'s
44 // "needs random access point" is read and updated as this method filters
45 // |buffers|. Buffers that are inside the append window are appended to the
46 // end of |filtered_buffers|. |track| must be the track associated with all
47 // items in |buffers|. |*new_media_segment| is set true if any of |buffers|
49 void FilterWithAppendWindow(base::TimeDelta append_window_start,
50 base::TimeDelta append_window_end,
51 const StreamParser::BufferQueue& buffers,
52 MseTrackBuffer* track,
53 bool* new_media_segment,
54 StreamParser::BufferQueue* filtered_buffers);
56 // Helper function that appends |buffers| to |stream| and calls
57 // |increase_duration_cb_| to potentially update the duration.
58 // Returns true if the append was successful. Returns false if
59 // |stream| is NULL or something in |buffers| caused the append to fail.
60 bool AppendAndUpdateDuration(ChunkDemuxerStream* stream,
61 const StreamParser::BufferQueue& buffers);
63 // Helper function for Legacy ProcessFrames() when new text buffers have been
65 // Applies |timestamp_offset| to all buffers in |buffers|, filters |buffers|
66 // with append window, and stores those filtered buffers into |filtered_text|
67 // based on |text_track_id|. If any of |buffers| are filtered out by append
68 // window, then |*new_media_segment| is set true.
69 // Updates |lowest_segment_timestamp| to be the earliest decode timestamp of
70 // all buffers in |filtered_text|.
71 // Returns true on a successful call. Returns false if an error occurred while
72 // processing the buffers.
73 bool FilterTextBuffers(StreamParser::TrackId text_track_id,
74 base::TimeDelta append_window_start,
75 base::TimeDelta append_window_end,
76 base::TimeDelta timestamp_offset,
77 const StreamParser::BufferQueue& buffers,
78 bool* new_media_segment,
79 base::TimeDelta* lowest_segment_timestamp,
80 StreamParser::TextBufferQueueMap* filtered_text);
82 IncreaseDurationCB increase_duration_cb_;
84 DISALLOW_COPY_AND_ASSIGN(LegacyFrameProcessor);
89 #endif // MEDIA_FILTERS_LEGACY_FRAME_PROCESSOR_H_