OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" | 5 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/ffmpeg/ffmpeg_common.h" | 8 #include "media/ffmpeg/ffmpeg_common.h" |
9 #include "media/formats/mp4/box_definitions.h" | 9 #include "media/formats/mp4/box_definitions.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 avc_config.reset(new mp4::AVCDecoderConfigurationRecord()); | 34 avc_config.reset(new mp4::AVCDecoderConfigurationRecord()); |
35 | 35 |
36 if (!converter_.ParseConfiguration( | 36 if (!converter_.ParseConfiguration( |
37 stream_codec_context_->extradata, | 37 stream_codec_context_->extradata, |
38 stream_codec_context_->extradata_size, | 38 stream_codec_context_->extradata_size, |
39 avc_config.get())) { | 39 avc_config.get())) { |
40 return false; | 40 return false; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 uint32 output_packet_size = converter_.CalculateNeededOutputBufferSize( | 44 uint32_t output_packet_size = converter_.CalculateNeededOutputBufferSize( |
45 packet->data, packet->size, avc_config.get()); | 45 packet->data, packet->size, avc_config.get()); |
46 | 46 |
47 if (output_packet_size == 0) | 47 if (output_packet_size == 0) |
48 return false; // Invalid input packet. | 48 return false; // Invalid input packet. |
49 | 49 |
50 // Allocate new packet for the output. | 50 // Allocate new packet for the output. |
51 AVPacket dest_packet; | 51 AVPacket dest_packet; |
52 if (av_new_packet(&dest_packet, output_packet_size) != 0) | 52 if (av_new_packet(&dest_packet, output_packet_size) != 0) |
53 return false; // Memory allocation failure. | 53 return false; // Memory allocation failure. |
54 | 54 |
55 // This is a bit tricky: since the interface does not allow us to replace | 55 // This is a bit tricky: since the interface does not allow us to replace |
56 // the pointer of the old packet with a new one, we will initially copy the | 56 // the pointer of the old packet with a new one, we will initially copy the |
57 // metadata from old packet to new bigger packet. | 57 // metadata from old packet to new bigger packet. |
58 av_packet_copy_props(&dest_packet, packet); | 58 av_packet_copy_props(&dest_packet, packet); |
59 | 59 |
60 // Proceed with the conversion of the actual in-band NAL units, leave room | 60 // Proceed with the conversion of the actual in-band NAL units, leave room |
61 // for configuration in the beginning. | 61 // for configuration in the beginning. |
62 uint32 io_size = dest_packet.size; | 62 uint32_t io_size = dest_packet.size; |
63 if (!converter_.ConvertNalUnitStreamToByteStream( | 63 if (!converter_.ConvertNalUnitStreamToByteStream( |
64 packet->data, packet->size, | 64 packet->data, packet->size, |
65 avc_config.get(), | 65 avc_config.get(), |
66 dest_packet.data, &io_size)) { | 66 dest_packet.data, &io_size)) { |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 if (avc_config) | 70 if (avc_config) |
71 configuration_processed_ = true; | 71 configuration_processed_ = true; |
72 | 72 |
73 // At the end we must destroy the old packet. | 73 // At the end we must destroy the old packet. |
74 av_packet_unref(packet); | 74 av_packet_unref(packet); |
75 *packet = dest_packet; // Finally, replace the values in the input packet. | 75 *packet = dest_packet; // Finally, replace the values in the input packet. |
76 | 76 |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 } // namespace media | 80 } // namespace media |
OLD | NEW |