webrtc/modules/video_coding
Shyam Sadhwani 5b2df17422 Width and Height was not associated and provided to decoder for H264 streams which have Nalus before SPS
Summary:
There is an issue with WebRTC for handling of certain H.264 bitstreams where the packets forming the H.264 stream has non-zero packets before the packet containing SPS.

Typically a IDR (key frame) will have SPS/PPS (if present) or the IDR slice in the first packet.
But this is not required in all cases, for example when packetization-mode = 0, you can have each NALU in separate packet. And certain NALUs can exist before SPS, for example SEI, AUD.

The way WebRTC associates width/height to encoded frames is by tracking the dependency of IDR slices to SPS/PPS.
RTP packets containing SPS/PPS have correct width/height stored in them during parsing of SPS in RtpDepacketizerH264::ProcessStapAOrSingleNalu
IDR packets refer to SPS using ppsid, spsid and the width/height fields get transferred from packet containing SPS to IDR packet in H264SpsPpsTracker::CopyAndFixBitstream.

When packets are assembled into a single encoded H264 frame in PacketBuffer::FindFrames, the loop goes through all the packets/nalus in backward scan from last RTP packet of IDR to first one.
Hence the order of NALUs during this scan is : Last parts of IDR Slice -> Mid parts of IDR Slice RTP packet -> first IDR slice Packet (this should have correct width / height) -> RTP packet containing SPS/PPS (this should have correct width/height)
start_index points to the first RTP packet of the frame and its passed into RtpFrameObject's constructor. RtpFrameObject will use the width/height stored in first RTP packet.

This works fine as long as the first RTP packet has width/height, which will be the case if first RTP packet is IDR or SPS.
In H.264 first RTP packet may be AUD, SEI in those cases, RtpFrameObject will create IDR with width/height = 0 and this causes problem for Android hardware decoders.
On Android hardware decoders rely on correct width/height to initialize the hardware decoder.

Verified on real scenario that we have.
Simulated on AppRTCMobile on IOS Simulator
Added unit tests : ninja -C out/Default && ./out/Default/modules_unittests --gtest_filter=*FrameResolution*

Bug: webrtc:11025
Change-Id: Ie2273aae5e81fd62497e1add084876a3aa05af4d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156260
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Commit-Queue: Shyam Sadhwani <shyamsadhwani@fb.com>
Cr-Commit-Position: refs/heads/master@{#29515}
2019-10-17 13:51:16 +00:00
..
codecs Merge SendTask implementation for SingleThreadedTaskQueueForTesting and TaskQueueForTest 2019-10-15 09:17:36 +00:00
include Cleanup includes in modules/include/module_common_types.h 2019-10-07 16:06:26 +00:00
test Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
utility Merge SendTask implementation for SingleThreadedTaskQueueForTesting and TaskQueueForTest 2019-10-15 09:17:36 +00:00
BUILD.gn Fix WebRTC-Video-MinVideoBitrate for VP9 2019-10-11 17:56:51 +00:00
codec_timer.cc [Cleanup] Add missing #include. Remove useless ones. IWYU part 2. 2018-11-28 18:25:07 +00:00
codec_timer.h Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
decoder_database.cc Format almost everything. 2019-07-08 13:45:15 +00:00
decoder_database.h Refactoring PayloadRouter. 2018-07-17 14:46:15 +00:00
decoding_state_unittest.cc Format almost everything. 2019-07-08 13:45:15 +00:00
decoding_state.cc Cleanup includes in modules/include/module_common_types.h 2019-10-07 16:06:26 +00:00
decoding_state.h Delete root header file typedef.h. 2018-07-25 14:59:26 +00:00
DEPS Prepare VideoProcessor for async simulcast support. 2018-03-08 17:41:13 +00:00
encoded_frame.cc Delete VCMEncodedFrame::VerifyAndAllocate 2019-10-04 14:16:49 +00:00
encoded_frame.h Cleanup includes in modules/include/module_common_types.h 2019-10-07 16:06:26 +00:00
fec_controller_default.cc Format almost everything. 2019-07-08 13:45:15 +00:00
fec_controller_default.h Format almost everything. 2019-07-08 13:45:15 +00:00
fec_controller_unittest.cc Format almost everything. 2019-07-08 13:45:15 +00:00
fec_rate_table.h
frame_buffer2_unittest.cc Delete VCMEncodedFrame::VerifyAndAllocate 2019-10-04 14:16:49 +00:00
frame_buffer2.cc Change FrameBuffer::CombineAndDeleteFrames to allocate a new buffer 2019-09-30 07:06:10 +00:00
frame_buffer2.h Control rtt_mult addition cap via experiment. 2019-06-07 09:43:26 +00:00
frame_buffer.cc Refactor legacy FrameBuffer to use EncodedImageBuffer::Realloc 2019-09-30 09:48:26 +00:00
frame_buffer.h Refactor legacy FrameBuffer to use EncodedImageBuffer::Realloc 2019-09-30 09:48:26 +00:00
frame_object.cc Remove unused RtpFrameObject ctor. 2019-10-01 11:23:26 +00:00
frame_object.h Remove unused RtpFrameObject ctor. 2019-10-01 11:23:26 +00:00
generic_decoder_unittest.cc Partially revert of ColorSpace information copying around decoders 2019-07-12 11:27:07 +00:00
generic_decoder.cc Add field-trial parameter to enable tests simulating a slow decoder 2019-09-11 11:08:59 +00:00
generic_decoder.h Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
h264_sprop_parameter_sets_unittest.cc Fully qualify googletest symbols. 2019-04-09 17:18:20 +00:00
h264_sprop_parameter_sets.cc Format almost everything. 2019-07-08 13:45:15 +00:00
h264_sprop_parameter_sets.h (4) Rename files to snake_case: update BUILD.gn, include paths, header guards, and DEPS entries 2019-01-11 17:11:39 +00:00
h264_sps_pps_tracker_unittest.cc Use nalus_length instead of is_first_packet_in_frame to insert startcodes in the H264SpsPpsTracker. 2019-07-12 14:04:26 +00:00
h264_sps_pps_tracker.cc Use nalus_length instead of is_first_packet_in_frame to insert startcodes in the H264SpsPpsTracker. 2019-07-12 14:04:26 +00:00
h264_sps_pps_tracker.h Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
histogram_unittest.cc Format almost everything. 2019-07-08 13:45:15 +00:00
histogram.cc [Cleanup] Add missing #include. Remove useless ones. IWYU part 2. 2018-11-28 18:25:07 +00:00
histogram.h
inter_frame_delay.cc Remove unused method in VCMInterFrameDelay. 2019-04-03 07:35:28 +00:00
inter_frame_delay.h Remove unused method in VCMInterFrameDelay. 2019-04-03 07:35:28 +00:00
internal_defines.h Remove unused defines and methods in internal_defines.h 2019-01-28 10:31:40 +00:00
jitter_buffer_common.h Format almost everything. 2019-07-08 13:45:15 +00:00
jitter_buffer_unittest.cc Format almost everything. 2019-07-08 13:45:15 +00:00
jitter_buffer.cc Trim dependencies in modules/video_coding/ 2019-09-11 09:31:10 +00:00
jitter_buffer.h Cleanup includes in modules/include/module_common_types.h 2019-10-07 16:06:26 +00:00
jitter_estimator_tests.cc Use std::make_unique instead of absl::make_unique. 2019-09-17 15:47:29 +00:00
jitter_estimator.cc Format almost everything. 2019-07-08 13:45:15 +00:00
jitter_estimator.h Add cap to video jitter buffer size/latency in experiment branches only. 2019-06-04 15:50:27 +00:00
loss_notification_controller_unittest.cc Refactor LossNotificationController to not use VCMPacket 2019-09-16 11:25:45 +00:00
loss_notification_controller.cc Refactor LossNotificationController to not use VCMPacket 2019-09-16 11:25:45 +00:00
loss_notification_controller.h Refactor LossNotificationController to not use VCMPacket 2019-09-16 11:25:45 +00:00
media_opt_util.cc Format almost everything. 2019-07-08 13:45:15 +00:00
media_opt_util.h Delete root header file typedef.h. 2018-07-25 14:59:26 +00:00
nack_module_unittest.cc Format almost everything. 2019-07-08 13:45:15 +00:00
nack_module.cc Format almost everything. 2019-07-08 13:45:15 +00:00
nack_module.h Format almost everything. 2019-07-08 13:45:15 +00:00
OWNERS Make ilnik@ owner in video/ and modules/video_coding/ 2018-09-11 12:39:39 +00:00
packet_buffer.cc Width and Height was not associated and provided to decoder for H264 streams which have Nalus before SPS 2019-10-17 13:51:16 +00:00
packet_buffer.h Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
packet.cc Add plumbing of RtpPacketInfos to each VideoFrame as input for SourceTracker. 2019-06-20 10:24:29 +00:00
packet.h Add plumbing of RtpPacketInfos to each VideoFrame as input for SourceTracker. 2019-06-20 10:24:29 +00:00
receiver_unittest.cc Delete some dead code in vcm::VideoReceiver and VCMReceiver 2019-09-10 12:40:58 +00:00
receiver.cc Delete some dead code in vcm::VideoReceiver and VCMReceiver 2019-09-10 12:40:58 +00:00
receiver.h Delete some dead code in vcm::VideoReceiver and VCMReceiver 2019-09-10 12:40:58 +00:00
rtp_frame_reference_finder_unittest.cc Use new RtpFrameObject ctor for unittests. 2019-09-30 08:28:45 +00:00
rtp_frame_reference_finder.cc Reset |reference_finder_| on codec switch. 2019-09-26 11:05:59 +00:00
rtp_frame_reference_finder.h Reset |reference_finder_| on codec switch. 2019-09-26 11:05:59 +00:00
rtt_filter.cc Fix typo in VCMRttFilter 2018-01-26 10:59:56 +00:00
rtt_filter.h Delete root header file typedef.h. 2018-07-25 14:59:26 +00:00
session_info_unittest.cc Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
session_info.cc Trim dependencies in modules/video_coding/ 2019-09-11 09:31:10 +00:00
session_info.h Format almost everything. 2019-07-08 13:45:15 +00:00
timestamp_map.cc Format almost everything. 2019-07-08 13:45:15 +00:00
timestamp_map.h Remove unimplemented function declarations VCMGenericDecoder::External and VCMTimestampMap::Reset. 2018-09-06 09:05:30 +00:00
timing_unittest.cc Format almost everything. 2019-07-08 13:45:15 +00:00
timing.cc Format almost everything. 2019-07-08 13:45:15 +00:00
timing.h Include module_common_types.h only where needed 2019-09-24 08:22:38 +00:00
video_codec_initializer_unittest.cc Update VideoBitrateAllocator allocate to take a struct with more fields 2019-08-02 13:52:54 +00:00
video_codec_initializer.cc Fix WebRTC-Video-MinVideoBitrate for VP9 2019-10-11 17:56:51 +00:00
video_coding_defines.cc Fix frames dropped statistics 2019-08-27 07:43:01 +00:00
video_coding_impl.cc Delete deprecated method VideoCodingModule::SetReceiverRobustnessMode 2019-06-12 06:39:38 +00:00
video_coding_impl.h Delete some dead code in vcm::VideoReceiver and VCMReceiver 2019-09-10 12:40:58 +00:00
video_packet_buffer_unittest.cc Width and Height was not associated and provided to decoder for H264 streams which have Nalus before SPS 2019-10-17 13:51:16 +00:00
video_receiver2.cc Delete VideoReceiver2::TriggerDecoderShutdown. 2019-09-12 13:44:13 +00:00
video_receiver2.h Delete VideoReceiver2::TriggerDecoderShutdown. 2019-09-12 13:44:13 +00:00
video_receiver_unittest.cc Change vcm::VideoReceiver::IncomingPacket to not use WebRtcRTPHeader 2019-04-25 10:15:39 +00:00
video_receiver.cc Delete some dead code in vcm::VideoReceiver and VCMReceiver 2019-09-10 12:40:58 +00:00