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

Side by Side Diff: media/base/stream_parser_buffer.h

Issue 447963003: Introduce DecodeTimestamp class to make it easier to distiguish presentation and decode timestamps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_BASE_STREAM_PARSER_BUFFER_H_ 5 #ifndef MEDIA_BASE_STREAM_PARSER_BUFFER_H_
6 #define MEDIA_BASE_STREAM_PARSER_BUFFER_H_ 6 #define MEDIA_BASE_STREAM_PARSER_BUFFER_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "media/base/decoder_buffer.h" 10 #include "media/base/decoder_buffer.h"
11 #include "media/base/demuxer_stream.h" 11 #include "media/base/demuxer_stream.h"
12 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
13 #include "media/base/stream_parser.h" 13 #include "media/base/stream_parser.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 // Simple wrapper around base::TimeDelta that represents a decode timestamp.
18 // Making DecodeTimestamp a different type makes it easier to determine whether
19 // code is operating on presentation or decode timestamps and makes conversions
20 // between the two types explicit and easy to spot.
21 class DecodeTimestamp {
22 public:
23 DecodeTimestamp() {};
wolenetz 2014/08/08 21:30:04 lint nit: s/;//
acolwell GONE FROM CHROMIUM 2014/08/11 17:05:05 Done.
24 DecodeTimestamp(const DecodeTimestamp& rhs) : ts_(rhs.ts_) { }
25 DecodeTimestamp& operator=(const DecodeTimestamp& rhs) {
26 if (&rhs != this)
27 ts_ = rhs.ts_;
28 return *this;
29 }
30
31 bool operator<(const DecodeTimestamp& rhs) const { return ts_ < rhs.ts_; }
32 bool operator>(const DecodeTimestamp& rhs) const { return ts_ > rhs.ts_; }
33 bool operator==(const DecodeTimestamp& rhs) const { return ts_ == rhs.ts_; }
34 bool operator!=(const DecodeTimestamp& rhs) const { return ts_ != rhs.ts_; }
35 bool operator>=(const DecodeTimestamp& rhs) const { return ts_ >= rhs.ts_; }
36 bool operator<=(const DecodeTimestamp& rhs) const { return ts_ <= rhs.ts_; }
37
38 base::TimeDelta operator-(const DecodeTimestamp& rhs) const {
39 return ts_ - rhs.ts_;
40 }
41
42 DecodeTimestamp& operator+=(const base::TimeDelta& rhs) {
43 ts_ += rhs;
44 return *this;
45 }
46
47 DecodeTimestamp& operator-=(const base::TimeDelta& rhs) {
48 ts_ -= rhs;
49 return *this;
50 }
51
52 DecodeTimestamp operator+(const base::TimeDelta& rhs) const {
wolenetz 2014/08/08 21:30:04 nit: Is there no expected need for adding two DTS?
acolwell GONE FROM CHROMIUM 2014/08/11 17:05:05 I can't think of any reason to do that. I've only
wolenetz 2014/08/12 00:09:00 Acknowledged.
53 return DecodeTimestamp(ts_ + rhs);
54 }
55
56 DecodeTimestamp operator-(const base::TimeDelta& rhs) const {
57 return DecodeTimestamp(ts_ - rhs);
58 }
59
60 int64 operator/(const base::TimeDelta& rhs) const {
wolenetz 2014/08/08 21:30:04 nit: Is there no expected need for dividing or mul
acolwell GONE FROM CHROMIUM 2014/08/11 17:05:05 I am only implementing operators that are actually
wolenetz 2014/08/12 00:09:00 Acknowledged.
61 return ts_ / rhs;
62 }
63
64 static DecodeTimestamp FromSecondsD(double seconds) {
65 return DecodeTimestamp(base::TimeDelta::FromSecondsD(seconds));
66 }
67
68 static DecodeTimestamp FromMilliseconds(int64 milliseconds) {
69 return DecodeTimestamp(base::TimeDelta::FromMilliseconds(milliseconds));
70 }
71
72 static DecodeTimestamp FromMicroseconds(int64 microseconds) {
73 return DecodeTimestamp(base::TimeDelta::FromMicroseconds(microseconds));
74 }
75
76 // This method is used to explicitly call out when presentation timestamps
77 // are being converted to a decode timestamp.
78 static DecodeTimestamp FromPresentationTime(base::TimeDelta timestamp) {
79 return DecodeTimestamp(timestamp);
80 }
81
82 double InSecondsF() const { return ts_.InSecondsF(); }
83 int64 InMilliseconds() const { return ts_.InMilliseconds(); }
84 int64 InMicroseconds() const { return ts_.InMicroseconds(); }
85
86 // TODO(acolwell): Remove once all the hacks are gone. This method is called
87 // by hacks where a decode time is being used as a presentation time.
88 base::TimeDelta ToPresentationTime() const { return ts_; }
89
90 private:
91 explicit DecodeTimestamp(base::TimeDelta timestamp) : ts_(timestamp) { }
92
93 base::TimeDelta ts_;
94 };
95
96 MEDIA_EXPORT extern inline DecodeTimestamp kNoDecodeTimestamp() {
97 return DecodeTimestamp::FromPresentationTime(kNoTimestamp());
98 }
99
17 class MEDIA_EXPORT StreamParserBuffer : public DecoderBuffer { 100 class MEDIA_EXPORT StreamParserBuffer : public DecoderBuffer {
18 public: 101 public:
19 // Value used to signal an invalid decoder config ID. 102 // Value used to signal an invalid decoder config ID.
20 enum { kInvalidConfigId = -1 }; 103 enum { kInvalidConfigId = -1 };
21 104
22 typedef DemuxerStream::Type Type; 105 typedef DemuxerStream::Type Type;
23 typedef StreamParser::TrackId TrackId; 106 typedef StreamParser::TrackId TrackId;
24 107
25 static scoped_refptr<StreamParserBuffer> CreateEOSBuffer(); 108 static scoped_refptr<StreamParserBuffer> CreateEOSBuffer();
26 109
27 static scoped_refptr<StreamParserBuffer> CopyFrom( 110 static scoped_refptr<StreamParserBuffer> CopyFrom(
28 const uint8* data, int data_size, bool is_keyframe, Type type, 111 const uint8* data, int data_size, bool is_keyframe, Type type,
29 TrackId track_id); 112 TrackId track_id);
30 static scoped_refptr<StreamParserBuffer> CopyFrom( 113 static scoped_refptr<StreamParserBuffer> CopyFrom(
31 const uint8* data, int data_size, 114 const uint8* data, int data_size,
32 const uint8* side_data, int side_data_size, bool is_keyframe, Type type, 115 const uint8* side_data, int side_data_size, bool is_keyframe, Type type,
33 TrackId track_id); 116 TrackId track_id);
34 bool IsKeyframe() const { return is_keyframe_; } 117 bool IsKeyframe() const { return is_keyframe_; }
35 118
36 // Decode timestamp. If not explicitly set, or set to kNoTimestamp(), the 119 // Decode timestamp. If not explicitly set, or set to kNoTimestamp(), the
37 // value will be taken from the normal timestamp. 120 // value will be taken from the normal timestamp.
38 base::TimeDelta GetDecodeTimestamp() const; 121 DecodeTimestamp GetDecodeTimestamp() const;
39 void SetDecodeTimestamp(base::TimeDelta timestamp); 122 void SetDecodeTimestamp(DecodeTimestamp timestamp);
40 123
41 // Gets/sets the ID of the decoder config associated with this buffer. 124 // Gets/sets the ID of the decoder config associated with this buffer.
42 int GetConfigId() const; 125 int GetConfigId() const;
43 void SetConfigId(int config_id); 126 void SetConfigId(int config_id);
44 127
45 // Gets the parser's media type associated with this buffer. Value is 128 // Gets the parser's media type associated with this buffer. Value is
46 // meaningless for EOS buffers. 129 // meaningless for EOS buffers.
47 Type type() const { return type_; } 130 Type type() const { return type_; }
48 131
49 // Gets the parser's track ID associated with this buffer. Value is 132 // Gets the parser's track ID associated with this buffer. Value is
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 virtual void set_timestamp(base::TimeDelta timestamp) OVERRIDE; 165 virtual void set_timestamp(base::TimeDelta timestamp) OVERRIDE;
83 166
84 private: 167 private:
85 StreamParserBuffer(const uint8* data, int data_size, 168 StreamParserBuffer(const uint8* data, int data_size,
86 const uint8* side_data, int side_data_size, 169 const uint8* side_data, int side_data_size,
87 bool is_keyframe, Type type, 170 bool is_keyframe, Type type,
88 TrackId track_id); 171 TrackId track_id);
89 virtual ~StreamParserBuffer(); 172 virtual ~StreamParserBuffer();
90 173
91 bool is_keyframe_; 174 bool is_keyframe_;
92 base::TimeDelta decode_timestamp_; 175 DecodeTimestamp decode_timestamp_;
93 int config_id_; 176 int config_id_;
94 Type type_; 177 Type type_;
95 TrackId track_id_; 178 TrackId track_id_;
96 BufferQueue splice_buffers_; 179 BufferQueue splice_buffers_;
97 scoped_refptr<StreamParserBuffer> preroll_buffer_; 180 scoped_refptr<StreamParserBuffer> preroll_buffer_;
98 181
99 DISALLOW_COPY_AND_ASSIGN(StreamParserBuffer); 182 DISALLOW_COPY_AND_ASSIGN(StreamParserBuffer);
100 }; 183 };
101 184
102 } // namespace media 185 } // namespace media
103 186
104 #endif // MEDIA_BASE_STREAM_PARSER_BUFFER_H_ 187 #endif // MEDIA_BASE_STREAM_PARSER_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698