OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 public rtc::MessageHandler { | 79 public rtc::MessageHandler { |
80 public: | 80 public: |
81 virtual ~MediaCodecVideoEncoder(); | 81 virtual ~MediaCodecVideoEncoder(); |
82 explicit MediaCodecVideoEncoder(JNIEnv* jni, VideoCodecType codecType); | 82 explicit MediaCodecVideoEncoder(JNIEnv* jni, VideoCodecType codecType); |
83 | 83 |
84 // webrtc::VideoEncoder implementation. Everything trampolines to | 84 // webrtc::VideoEncoder implementation. Everything trampolines to |
85 // |codec_thread_| for execution. | 85 // |codec_thread_| for execution. |
86 int32_t InitEncode(const webrtc::VideoCodec* codec_settings, | 86 int32_t InitEncode(const webrtc::VideoCodec* codec_settings, |
87 int32_t /* number_of_cores */, | 87 int32_t /* number_of_cores */, |
88 size_t /* max_payload_size */) override; | 88 size_t /* max_payload_size */) override; |
89 int32_t Encode( | 89 int32_t Encode(const webrtc::VideoFrame& input_image, |
90 const webrtc::VideoFrame& input_image, | 90 const webrtc::CodecSpecificInfo* /* codec_specific_info */, |
91 const webrtc::CodecSpecificInfo* /* codec_specific_info */, | 91 const std::vector<webrtc::FrameType>* frame_types) override; |
92 const std::vector<webrtc::VideoFrameType>* frame_types) override; | |
93 int32_t RegisterEncodeCompleteCallback( | 92 int32_t RegisterEncodeCompleteCallback( |
94 webrtc::EncodedImageCallback* callback) override; | 93 webrtc::EncodedImageCallback* callback) override; |
95 int32_t Release() override; | 94 int32_t Release() override; |
96 int32_t SetChannelParameters(uint32_t /* packet_loss */, | 95 int32_t SetChannelParameters(uint32_t /* packet_loss */, |
97 int64_t /* rtt */) override; | 96 int64_t /* rtt */) override; |
98 int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate) override; | 97 int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate) override; |
99 | 98 |
100 // rtc::MessageHandler implementation. | 99 // rtc::MessageHandler implementation. |
101 void OnMessage(rtc::Message* msg) override; | 100 void OnMessage(rtc::Message* msg) override; |
102 | 101 |
(...skipping 11 matching lines...) Expand all Loading... |
114 | 113 |
115 // Implementation of webrtc::VideoEncoder methods above, all running on the | 114 // Implementation of webrtc::VideoEncoder methods above, all running on the |
116 // codec thread exclusively. | 115 // codec thread exclusively. |
117 // | 116 // |
118 // If width==0 then this is assumed to be a re-initialization and the | 117 // If width==0 then this is assumed to be a re-initialization and the |
119 // previously-current values are reused instead of the passed parameters | 118 // previously-current values are reused instead of the passed parameters |
120 // (makes it easier to reason about thread-safety). | 119 // (makes it easier to reason about thread-safety). |
121 int32_t InitEncodeOnCodecThread(int width, int height, int kbps, int fps); | 120 int32_t InitEncodeOnCodecThread(int width, int height, int kbps, int fps); |
122 int32_t EncodeOnCodecThread( | 121 int32_t EncodeOnCodecThread( |
123 const webrtc::VideoFrame& input_image, | 122 const webrtc::VideoFrame& input_image, |
124 const std::vector<webrtc::VideoFrameType>* frame_types); | 123 const std::vector<webrtc::FrameType>* frame_types); |
125 int32_t RegisterEncodeCompleteCallbackOnCodecThread( | 124 int32_t RegisterEncodeCompleteCallbackOnCodecThread( |
126 webrtc::EncodedImageCallback* callback); | 125 webrtc::EncodedImageCallback* callback); |
127 int32_t ReleaseOnCodecThread(); | 126 int32_t ReleaseOnCodecThread(); |
128 int32_t SetRatesOnCodecThread(uint32_t new_bit_rate, uint32_t frame_rate); | 127 int32_t SetRatesOnCodecThread(uint32_t new_bit_rate, uint32_t frame_rate); |
129 | 128 |
130 // Helper accessors for MediaCodecVideoEncoder$OutputBufferInfo members. | 129 // Helper accessors for MediaCodecVideoEncoder$OutputBufferInfo members. |
131 int GetOutputBufferInfoIndex(JNIEnv* jni, jobject j_output_buffer_info); | 130 int GetOutputBufferInfoIndex(JNIEnv* jni, jobject j_output_buffer_info); |
132 jobject GetOutputBufferInfoBuffer(JNIEnv* jni, jobject j_output_buffer_info); | 131 jobject GetOutputBufferInfoBuffer(JNIEnv* jni, jobject j_output_buffer_info); |
133 bool GetOutputBufferInfoIsKeyFrame(JNIEnv* jni, jobject j_output_buffer_info); | 132 bool GetOutputBufferInfoIsKeyFrame(JNIEnv* jni, jobject j_output_buffer_info); |
134 jlong GetOutputBufferInfoPresentationTimestampUs( | 133 jlong GetOutputBufferInfoPresentationTimestampUs( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 this, | 330 this, |
332 codec_settings->width, | 331 codec_settings->width, |
333 codec_settings->height, | 332 codec_settings->height, |
334 codec_settings->startBitrate, | 333 codec_settings->startBitrate, |
335 codec_settings->maxFramerate)); | 334 codec_settings->maxFramerate)); |
336 } | 335 } |
337 | 336 |
338 int32_t MediaCodecVideoEncoder::Encode( | 337 int32_t MediaCodecVideoEncoder::Encode( |
339 const webrtc::VideoFrame& frame, | 338 const webrtc::VideoFrame& frame, |
340 const webrtc::CodecSpecificInfo* /* codec_specific_info */, | 339 const webrtc::CodecSpecificInfo* /* codec_specific_info */, |
341 const std::vector<webrtc::VideoFrameType>* frame_types) { | 340 const std::vector<webrtc::FrameType>* frame_types) { |
342 return codec_thread_->Invoke<int32_t>(Bind( | 341 return codec_thread_->Invoke<int32_t>(Bind( |
343 &MediaCodecVideoEncoder::EncodeOnCodecThread, this, frame, frame_types)); | 342 &MediaCodecVideoEncoder::EncodeOnCodecThread, this, frame, frame_types)); |
344 } | 343 } |
345 | 344 |
346 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback( | 345 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback( |
347 webrtc::EncodedImageCallback* callback) { | 346 webrtc::EncodedImageCallback* callback) { |
348 return codec_thread_->Invoke<int32_t>( | 347 return codec_thread_->Invoke<int32_t>( |
349 Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread, | 348 Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread, |
350 this, | 349 this, |
351 callback)); | 350 callback)); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; | 493 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; |
495 } | 494 } |
496 CHECK_EXCEPTION(jni); | 495 CHECK_EXCEPTION(jni); |
497 | 496 |
498 codec_thread_->PostDelayed(kMediaCodecPollMs, this); | 497 codec_thread_->PostDelayed(kMediaCodecPollMs, this); |
499 return WEBRTC_VIDEO_CODEC_OK; | 498 return WEBRTC_VIDEO_CODEC_OK; |
500 } | 499 } |
501 | 500 |
502 int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( | 501 int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( |
503 const webrtc::VideoFrame& frame, | 502 const webrtc::VideoFrame& frame, |
504 const std::vector<webrtc::VideoFrameType>* frame_types) { | 503 const std::vector<webrtc::FrameType>* frame_types) { |
505 CheckOnCodecThread(); | 504 CheckOnCodecThread(); |
506 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 505 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
507 ScopedLocalRefFrame local_ref_frame(jni); | 506 ScopedLocalRefFrame local_ref_frame(jni); |
508 | 507 |
509 if (!inited_) { | 508 if (!inited_) { |
510 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 509 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
511 } | 510 } |
512 frames_received_++; | 511 frames_received_++; |
513 if (!DeliverPendingOutputs(jni)) { | 512 if (!DeliverPendingOutputs(jni)) { |
514 ResetCodec(); | 513 ResetCodec(); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 } | 952 } |
954 | 953 |
955 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 954 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
956 webrtc::VideoEncoder* encoder) { | 955 webrtc::VideoEncoder* encoder) { |
957 ALOGD << "Destroy video encoder."; | 956 ALOGD << "Destroy video encoder."; |
958 delete encoder; | 957 delete encoder; |
959 } | 958 } |
960 | 959 |
961 } // namespace webrtc_jni | 960 } // namespace webrtc_jni |
962 | 961 |
OLD | NEW |