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

Side by Side Diff: webrtc/sdk/android/src/jni/androidmediaencoder_jni.cc

Issue 2772033002: Add content type information to encoded images and corresponding rtp extension header (Closed)
Patch Set: Set EncodedImage content_type from vie_encoder Created 3 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 int current_encoding_time_ms_; // Overall encoding time in the current second 235 int current_encoding_time_ms_; // Overall encoding time in the current second
236 int64_t last_input_timestamp_ms_; // Timestamp of last received yuv frame. 236 int64_t last_input_timestamp_ms_; // Timestamp of last received yuv frame.
237 int64_t last_output_timestamp_ms_; // Timestamp of last encoded frame. 237 int64_t last_output_timestamp_ms_; // Timestamp of last encoded frame.
238 // Holds the task while the polling loop is paused. 238 // Holds the task while the polling loop is paused.
239 std::unique_ptr<rtc::QueuedTask> encode_task_; 239 std::unique_ptr<rtc::QueuedTask> encode_task_;
240 240
241 struct InputFrameInfo { 241 struct InputFrameInfo {
242 InputFrameInfo(int64_t encode_start_time, 242 InputFrameInfo(int64_t encode_start_time,
243 int32_t frame_timestamp, 243 int32_t frame_timestamp,
244 int64_t frame_render_time_ms, 244 int64_t frame_render_time_ms,
245 webrtc::VideoRotation rotation) 245 webrtc::VideoRotation rotation,
246 webrtc::VideoContentTypeId content_type)
246 : encode_start_time(encode_start_time), 247 : encode_start_time(encode_start_time),
247 frame_timestamp(frame_timestamp), 248 frame_timestamp(frame_timestamp),
248 frame_render_time_ms(frame_render_time_ms), 249 frame_render_time_ms(frame_render_time_ms),
249 rotation(rotation) {} 250 rotation(rotation),
251 content_type(content_type) {}
250 // Time when video frame is sent to encoder input. 252 // Time when video frame is sent to encoder input.
251 const int64_t encode_start_time; 253 const int64_t encode_start_time;
252 254
253 // Input frame information. 255 // Input frame information.
254 const int32_t frame_timestamp; 256 const int32_t frame_timestamp;
255 const int64_t frame_render_time_ms; 257 const int64_t frame_render_time_ms;
256 const webrtc::VideoRotation rotation; 258 const webrtc::VideoRotation rotation;
259 const webrtc::VideoContentTypeId content_type;
257 }; 260 };
258 std::list<InputFrameInfo> input_frame_infos_; 261 std::list<InputFrameInfo> input_frame_infos_;
259 int32_t output_timestamp_; // Last output frame timestamp from 262 int32_t output_timestamp_; // Last output frame timestamp from
260 // |input_frame_infos_|. 263 // |input_frame_infos_|.
261 int64_t output_render_time_ms_; // Last output frame render time from 264 int64_t output_render_time_ms_; // Last output frame render time from
262 // |input_frame_infos_|. 265 // |input_frame_infos_|.
263 webrtc::VideoRotation output_rotation_; // Last output frame rotation from 266 webrtc::VideoRotation output_rotation_; // Last output frame rotation from
264 // |input_frame_infos_|. 267 // |input_frame_infos_|.
268 webrtc::VideoContentTypeId output_content_type_;
265 // Frame size in bytes fed to MediaCodec. 269 // Frame size in bytes fed to MediaCodec.
266 int yuv_size_; 270 int yuv_size_;
267 // True only when between a callback_->OnEncodedImage() call return a positive 271 // True only when between a callback_->OnEncodedImage() call return a positive
268 // value and the next Encode() call being ignored. 272 // value and the next Encode() call being ignored.
269 bool drop_next_input_frame_; 273 bool drop_next_input_frame_;
270 bool scale_; 274 bool scale_;
271 // Global references; must be deleted in Release(). 275 // Global references; must be deleted in Release().
272 std::vector<jobject> input_buffers_; 276 std::vector<jobject> input_buffers_;
273 webrtc::H264BitstreamParser h264_bitstream_parser_; 277 webrtc::H264BitstreamParser h264_bitstream_parser_;
274 278
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 } 706 }
703 frames_dropped_media_encoder_++; 707 frames_dropped_media_encoder_++;
704 return WEBRTC_VIDEO_CODEC_OK; 708 return WEBRTC_VIDEO_CODEC_OK;
705 } 709 }
706 consecutive_full_queue_frame_drops_ = 0; 710 consecutive_full_queue_frame_drops_ = 0;
707 711
708 rtc::scoped_refptr<webrtc::VideoFrameBuffer> input_buffer( 712 rtc::scoped_refptr<webrtc::VideoFrameBuffer> input_buffer(
709 frame.video_frame_buffer()); 713 frame.video_frame_buffer());
710 714
711 VideoFrame input_frame(input_buffer, frame.timestamp(), 715 VideoFrame input_frame(input_buffer, frame.timestamp(),
712 frame.render_time_ms(), frame.rotation()); 716 frame.render_time_ms(), frame.rotation(),
717 frame.content_type());
713 718
714 if (!MaybeReconfigureEncoder(input_frame)) { 719 if (!MaybeReconfigureEncoder(input_frame)) {
715 ALOGE << "Failed to reconfigure encoder."; 720 ALOGE << "Failed to reconfigure encoder.";
716 return WEBRTC_VIDEO_CODEC_ERROR; 721 return WEBRTC_VIDEO_CODEC_ERROR;
717 } 722 }
718 723
719 const bool key_frame = 724 const bool key_frame =
720 frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame; 725 frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame;
721 bool encode_status = true; 726 bool encode_status = true;
722 if (!input_frame.video_frame_buffer()->native_handle()) { 727 if (!input_frame.video_frame_buffer()->native_handle()) {
(...skipping 26 matching lines...) Expand all
749 } 754 }
750 755
751 if (!encode_status) { 756 if (!encode_status) {
752 ALOGE << "Failed encode frame with timestamp: " << input_frame.timestamp(); 757 ALOGE << "Failed encode frame with timestamp: " << input_frame.timestamp();
753 return ProcessHWErrorOnEncode(); 758 return ProcessHWErrorOnEncode();
754 } 759 }
755 760
756 // Save input image timestamps for later output. 761 // Save input image timestamps for later output.
757 input_frame_infos_.emplace_back(frame_input_time_ms, input_frame.timestamp(), 762 input_frame_infos_.emplace_back(frame_input_time_ms, input_frame.timestamp(),
758 input_frame.render_time_ms(), 763 input_frame.render_time_ms(),
759 input_frame.rotation()); 764 input_frame.rotation(),
765 input_frame.content_type());
760 766
761 last_input_timestamp_ms_ = 767 last_input_timestamp_ms_ =
762 current_timestamp_us_ / rtc::kNumMicrosecsPerMillisec; 768 current_timestamp_us_ / rtc::kNumMicrosecsPerMillisec;
763 769
764 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; 770 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
765 771
766 // Start the polling loop if it is not started. 772 // Start the polling loop if it is not started.
767 if (encode_task_) { 773 if (encode_task_) {
768 rtc::TaskQueue::Current()->PostDelayedTask(std::move(encode_task_), 774 rtc::TaskQueue::Current()->PostDelayedTask(std::move(encode_task_),
769 kMediaCodecPollMs); 775 kMediaCodecPollMs);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 int64_t encoding_start_time_ms = 0; 1006 int64_t encoding_start_time_ms = 0;
1001 int64_t frame_encoding_time_ms = 0; 1007 int64_t frame_encoding_time_ms = 0;
1002 last_output_timestamp_ms_ = 1008 last_output_timestamp_ms_ =
1003 GetOutputBufferInfoPresentationTimestampUs(jni, j_output_buffer_info) / 1009 GetOutputBufferInfoPresentationTimestampUs(jni, j_output_buffer_info) /
1004 rtc::kNumMicrosecsPerMillisec; 1010 rtc::kNumMicrosecsPerMillisec;
1005 if (!input_frame_infos_.empty()) { 1011 if (!input_frame_infos_.empty()) {
1006 const InputFrameInfo& frame_info = input_frame_infos_.front(); 1012 const InputFrameInfo& frame_info = input_frame_infos_.front();
1007 output_timestamp_ = frame_info.frame_timestamp; 1013 output_timestamp_ = frame_info.frame_timestamp;
1008 output_render_time_ms_ = frame_info.frame_render_time_ms; 1014 output_render_time_ms_ = frame_info.frame_render_time_ms;
1009 output_rotation_ = frame_info.rotation; 1015 output_rotation_ = frame_info.rotation;
1016 output_content_type_ = frame_info.content_type;
1010 encoding_start_time_ms = frame_info.encode_start_time; 1017 encoding_start_time_ms = frame_info.encode_start_time;
1011 input_frame_infos_.pop_front(); 1018 input_frame_infos_.pop_front();
1012 } 1019 }
1013 1020
1014 // Extract payload. 1021 // Extract payload.
1015 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); 1022 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer);
1016 uint8_t* payload = reinterpret_cast<uint8_t*>( 1023 uint8_t* payload = reinterpret_cast<uint8_t*>(
1017 jni->GetDirectBufferAddress(j_output_buffer)); 1024 jni->GetDirectBufferAddress(j_output_buffer));
1018 if (CheckException(jni)) { 1025 if (CheckException(jni)) {
1019 ALOGE << "Exception in get direct buffer address."; 1026 ALOGE << "Exception in get direct buffer address.";
1020 ProcessHWError(true /* reset_if_fallback_unavailable */); 1027 ProcessHWError(true /* reset_if_fallback_unavailable */);
1021 return WEBRTC_VIDEO_CODEC_ERROR; 1028 return WEBRTC_VIDEO_CODEC_ERROR;
1022 } 1029 }
1023 1030
1024 // Callback - return encoded frame. 1031 // Callback - return encoded frame.
1025 const VideoCodecType codec_type = 1032 const VideoCodecType codec_type =
1026 webrtc::PayloadNameToCodecType(codec_.name) 1033 webrtc::PayloadNameToCodecType(codec_.name)
1027 .value_or(webrtc::kVideoCodecUnknown); 1034 .value_or(webrtc::kVideoCodecUnknown);
1028 webrtc::EncodedImageCallback::Result callback_result( 1035 webrtc::EncodedImageCallback::Result callback_result(
1029 webrtc::EncodedImageCallback::Result::OK); 1036 webrtc::EncodedImageCallback::Result::OK);
1030 if (callback_) { 1037 if (callback_) {
1031 std::unique_ptr<webrtc::EncodedImage> image( 1038 std::unique_ptr<webrtc::EncodedImage> image(
1032 new webrtc::EncodedImage(payload, payload_size, payload_size)); 1039 new webrtc::EncodedImage(payload, payload_size, payload_size));
1033 image->_encodedWidth = width_; 1040 image->_encodedWidth = width_;
1034 image->_encodedHeight = height_; 1041 image->_encodedHeight = height_;
1035 image->_timeStamp = output_timestamp_; 1042 image->_timeStamp = output_timestamp_;
1036 image->capture_time_ms_ = output_render_time_ms_; 1043 image->capture_time_ms_ = output_render_time_ms_;
1037 image->rotation_ = output_rotation_; 1044 image->rotation_ = output_rotation_;
1045 image->content_type_ = output_content_type_;
1038 image->_frameType = 1046 image->_frameType =
1039 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); 1047 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta);
1040 image->_completeFrame = true; 1048 image->_completeFrame = true;
1041 webrtc::CodecSpecificInfo info; 1049 webrtc::CodecSpecificInfo info;
1042 memset(&info, 0, sizeof(info)); 1050 memset(&info, 0, sizeof(info));
1043 info.codecType = codec_type; 1051 info.codecType = codec_type;
1044 if (codec_type == kVideoCodecVP8) { 1052 if (codec_type == kVideoCodecVP8) {
1045 info.codecSpecific.VP8.pictureId = picture_id_; 1053 info.codecSpecific.VP8.pictureId = picture_id_;
1046 info.codecSpecific.VP8.nonReference = false; 1054 info.codecSpecific.VP8.nonReference = false;
1047 info.codecSpecific.VP8.simulcastIdx = 0; 1055 info.codecSpecific.VP8.simulcastIdx = 0;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 } 1319 }
1312 } 1320 }
1313 1321
1314 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( 1322 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder(
1315 webrtc::VideoEncoder* encoder) { 1323 webrtc::VideoEncoder* encoder) {
1316 ALOGD << "Destroy video encoder."; 1324 ALOGD << "Destroy video encoder.";
1317 delete encoder; 1325 delete encoder;
1318 } 1326 }
1319 1327
1320 } // namespace webrtc_jni 1328 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698