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_CAST_SENDER_RTP_TIMESTAMP_HELPER_H_ | 5 #ifndef MEDIA_CAST_SENDER_RTP_TIMESTAMP_HELPER_H_ |
6 #define MEDIA_CAST_SENDER_RTP_TIMESTAMP_HELPER_H_ | 6 #define MEDIA_CAST_SENDER_RTP_TIMESTAMP_HELPER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 namespace cast { | 12 namespace cast { |
13 | 13 |
14 // A helper class used to convert current time ticks into RTP timestamp. | 14 // A helper class used to convert current time ticks into RTP timestamp. |
15 class RtpTimestampHelper { | 15 class RtpTimestampHelper { |
16 public: | 16 public: |
17 explicit RtpTimestampHelper(int frequency); | 17 explicit RtpTimestampHelper(int frequency); |
18 ~RtpTimestampHelper(); | 18 ~RtpTimestampHelper(); |
19 | 19 |
20 // Compute a RTP timestamp using current time, last encoded time and | 20 // Compute a RTP timestamp from a TimeTicks, or a TimeTicks from a RTP |
21 // last encoded RTP timestamp. | 21 // timestamp; based on the currently stored capture time and its corresponding |
22 // Return true if |rtp_timestamp| is computed. | 22 // RTP timestamp. Return true if |rtp_timestamp| is computed. |
23 bool GetCurrentTimeAsRtpTimestamp(const base::TimeTicks& now, | 23 // |
24 uint32* rtp_timestamp) const; | 24 // The values are estimates because, ultimately, it's the encoders that decide |
| 25 // what the RTP timestamps for each frame are going to be. For example, in |
| 26 // the case of audio, the TimeTicks may never be precise to an exact frame |
| 27 // boundary; and so the computation here will result in a |rtp_timestamp| |
| 28 // value that is near, but never exact to one emitted by the encoder. |
| 29 bool EstimateRtpTimestamp(const base::TimeTicks& t, |
| 30 uint32* rtp_timestamp) const; |
| 31 bool EstimateTimeTicks(uint32 rtp_timestamp, base::TimeTicks* t) const; |
25 | 32 |
26 // Store the capture time and the corresponding RTP timestamp for the | 33 // Store the capture time and the corresponding RTP timestamp for the |
27 // last encoded frame. | 34 // last encoded frame. |
28 void StoreLatestTime(base::TimeTicks capture_time, uint32 rtp_timestamp); | 35 void StoreLatestTime(base::TimeTicks capture_time, uint32 rtp_timestamp); |
29 | 36 |
30 private: | 37 private: |
31 int frequency_; | 38 int frequency_; |
32 base::TimeTicks last_capture_time_; | 39 base::TimeTicks last_capture_time_; |
33 uint32 last_rtp_timestamp_; | 40 uint32 last_rtp_timestamp_; |
34 | 41 |
35 DISALLOW_COPY_AND_ASSIGN(RtpTimestampHelper); | 42 DISALLOW_COPY_AND_ASSIGN(RtpTimestampHelper); |
36 }; | 43 }; |
37 | 44 |
38 } // namespace cast | 45 } // namespace cast |
39 } // namespace media | 46 } // namespace media |
40 | 47 |
41 #endif // MEDIA_CAST_SENDER_RTP_TIMESTAMP_HELPER_H_ | 48 #endif // MEDIA_CAST_SENDER_RTP_TIMESTAMP_HELPER_H_ |
OLD | NEW |