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

Side by Side Diff: media/formats/webm/webm_cluster_parser.h

Issue 213253006: MSE: Populate WebM missing duration with DefaultDuration, derived, or default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 5 #ifndef MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 10 matching lines...) Expand all
21 namespace media { 21 namespace media {
22 22
23 class MEDIA_EXPORT WebMClusterParser : public WebMParserClient { 23 class MEDIA_EXPORT WebMClusterParser : public WebMParserClient {
24 public: 24 public:
25 typedef StreamParser::TrackId TrackId; 25 typedef StreamParser::TrackId TrackId;
26 26
27 private: 27 private:
28 // Helper class that manages per-track state. 28 // Helper class that manages per-track state.
29 class Track { 29 class Track {
30 public: 30 public:
31 Track(int track_num, bool is_video); 31 Track(int track_num, bool is_video, base::TimeDelta default_duration);
32 ~Track(); 32 ~Track();
33 33
34 int track_num() const { return track_num_; } 34 int track_num() const { return track_num_; }
35 const std::deque<scoped_refptr<StreamParserBuffer> >& buffers() const { 35 const std::deque<scoped_refptr<StreamParserBuffer> >& buffers() const {
36 return buffers_; 36 return buffers_;
37 } 37 }
38 38
39 // If |last_added_buffer_missing_duration_| is set, updates its duration
40 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets
41 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing
42 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or
43 // otherwise adds |buffer| to |buffers_|.
39 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer); 44 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer);
40 45
41 // Clears all buffer state. 46 // If |last_added_buffer_missing_duration_| is set, updates its duration
47 // to be the first non-kNoTimestamp() value of |default_duration_|,
48 // |estimated_next_frame_duration_|, or an arbitrary default, then adds it
49 // to |buffers_| and unsets |last_added_buffer_missing_duration_|. (This
50 // method helps stream parser emit all buffers in a media segment before
51 // signaling end of segment.)
52 void ApplyDurationDefaultOrEstimateIfNeeded();
53
54 // Clears all buffer state, except a possibly held-aside buffer that is
55 // missing duration.
42 void Reset(); 56 void Reset();
43 57
58 // Clears all buffer state, including any possibly held-aside buffer that
59 // was missing duration.
60 void Flush();
61
44 // Helper function used to inspect block data to determine if the 62 // Helper function used to inspect block data to determine if the
45 // block is a keyframe. 63 // block is a keyframe.
46 // |data| contains the bytes in the block. 64 // |data| contains the bytes in the block.
47 // |size| indicates the number of bytes in |data|. 65 // |size| indicates the number of bytes in |data|.
48 bool IsKeyframe(const uint8* data, int size) const; 66 bool IsKeyframe(const uint8* data, int size) const;
49 67
50 private: 68 private:
51 int track_num_; 69 int track_num_;
52 std::deque<scoped_refptr<StreamParserBuffer> > buffers_; 70 std::deque<scoped_refptr<StreamParserBuffer> > buffers_;
53 bool is_video_; 71 bool is_video_;
72 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_;
73
74 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used.
75 base::TimeDelta default_duration_;
76 // If kNoTimestamp(), then a default value will be used. This estimate is
77 // the maximum duration seen or derived so far for this track, and is valid
78 // only if |default_duration_| is kNoTimestamp().
79 base::TimeDelta estimated_next_frame_duration_;
54 }; 80 };
55 81
56 typedef std::map<int, Track> TextTrackMap; 82 typedef std::map<int, Track> TextTrackMap;
57 83
58 public: 84 public:
59 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; 85 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue;
60 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap; 86 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap;
61 87
62 WebMClusterParser(int64 timecode_scale, 88 WebMClusterParser(int64 timecode_scale,
63 int audio_track_num, 89 int audio_track_num,
90 base::TimeDelta audio_default_duration,
64 int video_track_num, 91 int video_track_num,
92 base::TimeDelta video_default_duration,
65 const WebMTracksParser::TextTracks& text_tracks, 93 const WebMTracksParser::TextTracks& text_tracks,
66 const std::set<int64>& ignored_tracks, 94 const std::set<int64>& ignored_tracks,
67 const std::string& audio_encryption_key_id, 95 const std::string& audio_encryption_key_id,
68 const std::string& video_encryption_key_id, 96 const std::string& video_encryption_key_id,
69 const LogCB& log_cb); 97 const LogCB& log_cb);
70 virtual ~WebMClusterParser(); 98 virtual ~WebMClusterParser();
71 99
72 // Resets the parser state so it can accept a new cluster. 100 // Resets the parser state so it can accept a new cluster.
73 void Reset(); 101 void Reset();
74 102
75 // Parses a WebM cluster element in |buf|. 103 // Parses a WebM cluster element in |buf|.
76 // 104 //
77 // Returns -1 if the parse fails. 105 // Returns -1 if the parse fails.
78 // Returns 0 if more data is needed. 106 // Returns 0 if more data is needed.
79 // Returns the number of bytes parsed on success. 107 // Returns the number of bytes parsed on success.
80 int Parse(const uint8* buf, int size); 108 int Parse(const uint8* buf, int size);
81 109
82 base::TimeDelta cluster_start_time() const { return cluster_start_time_; } 110 base::TimeDelta cluster_start_time() const { return cluster_start_time_; }
83 const BufferQueue& audio_buffers() const { return audio_.buffers(); } 111
84 const BufferQueue& video_buffers() const { return video_.buffers(); } 112 // Get the buffers resulting from Parse().
113 // If the parse reached the end of cluster and the last buffer was held aside
114 // due to missing duration, the buffer is given an estimated duration and
115 // included in the result.
116 const BufferQueue& GetAudioBuffers();
117 const BufferQueue& GetVideoBuffers();
85 118
86 // Constructs and returns a subset of |text_track_map_| containing only 119 // Constructs and returns a subset of |text_track_map_| containing only
87 // tracks with non-empty buffer queues produced by the last Parse(). 120 // tracks with non-empty buffer queues produced by the last Parse().
88 // The returned map is cleared by Parse() or Reset() and updated by the next 121 // The returned map is cleared by Parse() or Reset() and updated by the next
89 // call to GetTextBuffers(). 122 // call to GetTextBuffers().
90 const TextBufferQueueMap& GetTextBuffers(); 123 const TextBufferQueueMap& GetTextBuffers();
91 124
92 // Returns true if the last Parse() call stopped at the end of a cluster. 125 // Returns true if the last Parse() call stopped at the end of a cluster.
93 bool cluster_ended() const { return cluster_ended_; } 126 bool cluster_ended() const { return cluster_ended_; }
94 127
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 TextBufferQueueMap text_buffers_map_; 179 TextBufferQueueMap text_buffers_map_;
147 180
148 LogCB log_cb_; 181 LogCB log_cb_;
149 182
150 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); 183 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser);
151 }; 184 };
152 185
153 } // namespace media 186 } // namespace media
154 187
155 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 188 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698