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