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 #include "media/cast/sender/h264_vt_encoder.h" | 5 #include "media/cast/sender/h264_vt_encoder.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/power_monitor/power_monitor.h" | 16 #include "base/power_monitor/power_monitor.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "media/base/mac/corevideo_glue.h" | 18 #include "media/base/mac/corevideo_glue.h" |
19 #include "media/base/mac/video_frame_mac.h" | 19 #include "media/base/mac/video_frame_mac.h" |
20 #include "media/cast/cast_defines.h" | 20 #include "media/cast/common/rtp_time.h" |
21 #include "media/cast/constants.h" | 21 #include "media/cast/constants.h" |
22 #include "media/cast/sender/video_frame_factory.h" | 22 #include "media/cast/sender/video_frame_factory.h" |
23 | 23 |
24 namespace media { | 24 namespace media { |
25 namespace cast { | 25 namespace cast { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Container for the associated data of a video frame being processed. | 29 // Container for the associated data of a video frame being processed. |
30 struct InProgressFrameEncode { | 30 struct InProgressFrameEncode { |
31 const RtpTimestamp rtp_timestamp; | 31 const RtpTimeTicks rtp_timestamp; |
32 const base::TimeTicks reference_time; | 32 const base::TimeTicks reference_time; |
33 const VideoEncoder::FrameEncodedCallback frame_encoded_callback; | 33 const VideoEncoder::FrameEncodedCallback frame_encoded_callback; |
34 | 34 |
35 InProgressFrameEncode(RtpTimestamp rtp, | 35 InProgressFrameEncode(RtpTimeTicks rtp, |
36 base::TimeTicks r_time, | 36 base::TimeTicks r_time, |
37 VideoEncoder::FrameEncodedCallback callback) | 37 VideoEncoder::FrameEncodedCallback callback) |
38 : rtp_timestamp(rtp), | 38 : rtp_timestamp(rtp), |
39 reference_time(r_time), | 39 reference_time(r_time), |
40 frame_encoded_callback(callback) {} | 40 frame_encoded_callback(callback) {} |
41 }; | 41 }; |
42 | 42 |
43 base::ScopedCFTypeRef<CFDictionaryRef> | 43 base::ScopedCFTypeRef<CFDictionaryRef> |
44 DictionaryWithKeysAndValues(CFTypeRef* keys, CFTypeRef* values, size_t size) { | 44 DictionaryWithKeysAndValues(CFTypeRef* keys, CFTypeRef* values, size_t size) { |
45 return base::ScopedCFTypeRef<CFDictionaryRef>(CFDictionaryCreate( | 45 return base::ScopedCFTypeRef<CFDictionaryRef>(CFDictionaryCreate( |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 return false; | 561 return false; |
562 } | 562 } |
563 | 563 |
564 // Convert the frame timestamp to CMTime. | 564 // Convert the frame timestamp to CMTime. |
565 auto timestamp_cm = CoreMediaGlue::CMTimeMake( | 565 auto timestamp_cm = CoreMediaGlue::CMTimeMake( |
566 (reference_time - base::TimeTicks()).InMicroseconds(), USEC_PER_SEC); | 566 (reference_time - base::TimeTicks()).InMicroseconds(), USEC_PER_SEC); |
567 | 567 |
568 // Wrap information we'll need after the frame is encoded in a heap object. | 568 // Wrap information we'll need after the frame is encoded in a heap object. |
569 // We'll get the pointer back from the VideoToolbox completion callback. | 569 // We'll get the pointer back from the VideoToolbox completion callback. |
570 scoped_ptr<InProgressFrameEncode> request(new InProgressFrameEncode( | 570 scoped_ptr<InProgressFrameEncode> request(new InProgressFrameEncode( |
571 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency), | 571 RtpTimeTicks::FromTimeDelta(video_frame->timestamp(), kVideoFrequency), |
572 reference_time, frame_encoded_callback)); | 572 reference_time, frame_encoded_callback)); |
573 | 573 |
574 // Build a suitable frame properties dictionary for keyframes. | 574 // Build a suitable frame properties dictionary for keyframes. |
575 base::ScopedCFTypeRef<CFDictionaryRef> frame_props; | 575 base::ScopedCFTypeRef<CFDictionaryRef> frame_props; |
576 if (encode_next_frame_as_keyframe_) { | 576 if (encode_next_frame_as_keyframe_) { |
577 frame_props = DictionaryWithKeyValue( | 577 frame_props = DictionaryWithKeyValue( |
578 videotoolbox_glue_->kVTEncodeFrameOptionKey_ForceKeyFrame(), | 578 videotoolbox_glue_->kVTEncodeFrameOptionKey_ForceKeyFrame(), |
579 kCFBooleanTrue); | 579 kCFBooleanTrue); |
580 encode_next_frame_as_keyframe_ = false; | 580 encode_next_frame_as_keyframe_ = false; |
581 } | 581 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 encoded_frame->encode_completion_time = | 757 encoded_frame->encode_completion_time = |
758 encoder->cast_environment_->Clock()->NowTicks(); | 758 encoder->cast_environment_->Clock()->NowTicks(); |
759 encoder->cast_environment_->PostTask( | 759 encoder->cast_environment_->PostTask( |
760 CastEnvironment::MAIN, FROM_HERE, | 760 CastEnvironment::MAIN, FROM_HERE, |
761 base::Bind(request->frame_encoded_callback, | 761 base::Bind(request->frame_encoded_callback, |
762 base::Passed(&encoded_frame))); | 762 base::Passed(&encoded_frame))); |
763 } | 763 } |
764 | 764 |
765 } // namespace cast | 765 } // namespace cast |
766 } // namespace media | 766 } // namespace media |
OLD | NEW |