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

Side by Side Diff: media/filters/ffmpeg_aac_bitstream_converter_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 // 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/ffmpeg/ffmpeg_common.h" 5 #include "media/ffmpeg/ffmpeg_common.h"
6 #include "media/filters/ffmpeg_aac_bitstream_converter.h" 6 #include "media/filters/ffmpeg_aac_bitstream_converter.h"
7 #include "media/filters/ffmpeg_demuxer.h" 7 #include "media/filters/ffmpeg_demuxer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 12 matching lines...) Expand all
23 23
24 // Set up reasonable aac context 24 // Set up reasonable aac context
25 memset(&test_context_, 0, sizeof(AVCodecContext)); 25 memset(&test_context_, 0, sizeof(AVCodecContext));
26 test_context_.codec_id = AV_CODEC_ID_AAC; 26 test_context_.codec_id = AV_CODEC_ID_AAC;
27 test_context_.profile = FF_PROFILE_AAC_MAIN; 27 test_context_.profile = FF_PROFILE_AAC_MAIN;
28 test_context_.channels = 2; 28 test_context_.channels = 2;
29 test_context_.extradata = context_header_; 29 test_context_.extradata = context_header_;
30 test_context_.extradata_size = sizeof(context_header_); 30 test_context_.extradata_size = sizeof(context_header_);
31 } 31 }
32 32
33 void CreatePacket(AVPacket* packet, const uint8* data, uint32 data_size) { 33 void CreatePacket(AVPacket* packet, const uint8_t* data, uint32_t data_size) {
34 // Create new packet sized of |data_size| from |data|. 34 // Create new packet sized of |data_size| from |data|.
35 EXPECT_EQ(av_new_packet(packet, data_size), 0); 35 EXPECT_EQ(av_new_packet(packet, data_size), 0);
36 memcpy(packet->data, data, data_size); 36 memcpy(packet->data, data, data_size);
37 } 37 }
38 38
39 // Variable to hold valid dummy context for testing. 39 // Variable to hold valid dummy context for testing.
40 AVCodecContext test_context_; 40 AVCodecContext test_context_;
41 41
42 private: 42 private:
43 uint8 context_header_[2]; 43 uint8_t context_header_[2];
44 44
45 DISALLOW_COPY_AND_ASSIGN(FFmpegAACBitstreamConverterTest); 45 DISALLOW_COPY_AND_ASSIGN(FFmpegAACBitstreamConverterTest);
46 }; 46 };
47 47
48 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_Success) { 48 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_Success) {
49 FFmpegAACBitstreamConverter converter(&test_context_); 49 FFmpegAACBitstreamConverter converter(&test_context_);
50 50
51 uint8 dummy_packet[1000]; 51 uint8_t dummy_packet[1000];
52 // Fill dummy packet with junk data. aac converter doesn't look into packet 52 // Fill dummy packet with junk data. aac converter doesn't look into packet
53 // data, just header, so can fill with whatever we want for test. 53 // data, just header, so can fill with whatever we want for test.
54 for(size_t i = 0; i < sizeof(dummy_packet); i++) { 54 for(size_t i = 0; i < sizeof(dummy_packet); i++) {
55 dummy_packet[i] = i & 0xFF; // Repeated sequences of 0-255 55 dummy_packet[i] = i & 0xFF; // Repeated sequences of 0-255
56 } 56 }
57 57
58 ScopedAVPacket test_packet(new AVPacket()); 58 ScopedAVPacket test_packet(new AVPacket());
59 CreatePacket(test_packet.get(), dummy_packet, 59 CreatePacket(test_packet.get(), dummy_packet,
60 sizeof(dummy_packet)); 60 sizeof(dummy_packet));
61 61
(...skipping 12 matching lines...) Expand all
74 sizeof(dummy_packet)), 0); 74 sizeof(dummy_packet)), 0);
75 } 75 }
76 76
77 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_FailureNullParams) { 77 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_FailureNullParams) {
78 // Set up AVCConfigurationRecord to represent NULL data. 78 // Set up AVCConfigurationRecord to represent NULL data.
79 AVCodecContext dummy_context; 79 AVCodecContext dummy_context;
80 dummy_context.extradata = NULL; 80 dummy_context.extradata = NULL;
81 dummy_context.extradata_size = 0; 81 dummy_context.extradata_size = 0;
82 FFmpegAACBitstreamConverter converter(&dummy_context); 82 FFmpegAACBitstreamConverter converter(&dummy_context);
83 83
84 uint8 dummy_packet[1000] = {0}; 84 uint8_t dummy_packet[1000] = {0};
85 85
86 // Try out the actual conversion with NULL parameter. 86 // Try out the actual conversion with NULL parameter.
87 EXPECT_FALSE(converter.ConvertPacket(NULL)); 87 EXPECT_FALSE(converter.ConvertPacket(NULL));
88 88
89 // Create new packet to test actual conversion. 89 // Create new packet to test actual conversion.
90 ScopedAVPacket test_packet(new AVPacket()); 90 ScopedAVPacket test_packet(new AVPacket());
91 CreatePacket(test_packet.get(), dummy_packet, sizeof(dummy_packet)); 91 CreatePacket(test_packet.get(), dummy_packet, sizeof(dummy_packet));
92 92
93 // Try out the actual conversion. This should fail due to missing extradata. 93 // Try out the actual conversion. This should fail due to missing extradata.
94 EXPECT_FALSE(converter.ConvertPacket(test_packet.get())); 94 EXPECT_FALSE(converter.ConvertPacket(test_packet.get()));
95 } 95 }
96 96
97 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_AudioProfileType) { 97 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_AudioProfileType) {
98 FFmpegAACBitstreamConverter converter(&test_context_); 98 FFmpegAACBitstreamConverter converter(&test_context_);
99 99
100 uint8 dummy_packet[1000] = {0}; 100 uint8_t dummy_packet[1000] = {0};
101 101
102 ScopedAVPacket test_packet(new AVPacket()); 102 ScopedAVPacket test_packet(new AVPacket());
103 CreatePacket(test_packet.get(), dummy_packet, 103 CreatePacket(test_packet.get(), dummy_packet,
104 sizeof(dummy_packet)); 104 sizeof(dummy_packet));
105 105
106 EXPECT_TRUE(converter.ConvertPacket(test_packet.get())); 106 EXPECT_TRUE(converter.ConvertPacket(test_packet.get()));
107 107
108 // Check that the ADTS header profile matches the context 108 // Check that the ADTS header profile matches the context
109 int profile = ((test_packet->data[2] & 0xC0) >> 6); 109 int profile = ((test_packet->data[2] & 0xC0) >> 6);
110 110
(...skipping 18 matching lines...) Expand all
129 test_packet.reset(new AVPacket()); 129 test_packet.reset(new AVPacket());
130 CreatePacket(test_packet.get(), dummy_packet, 130 CreatePacket(test_packet.get(), dummy_packet,
131 sizeof(dummy_packet)); 131 sizeof(dummy_packet));
132 132
133 EXPECT_FALSE(converter_eld.ConvertPacket(test_packet.get())); 133 EXPECT_FALSE(converter_eld.ConvertPacket(test_packet.get()));
134 } 134 }
135 135
136 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_MultipleLength) { 136 TEST_F(FFmpegAACBitstreamConverterTest, Conversion_MultipleLength) {
137 FFmpegAACBitstreamConverter converter(&test_context_); 137 FFmpegAACBitstreamConverter converter(&test_context_);
138 138
139 uint8 dummy_packet[1000]; 139 uint8_t dummy_packet[1000];
140 140
141 ScopedAVPacket test_packet(new AVPacket()); 141 ScopedAVPacket test_packet(new AVPacket());
142 CreatePacket(test_packet.get(), dummy_packet, 142 CreatePacket(test_packet.get(), dummy_packet,
143 sizeof(dummy_packet)); 143 sizeof(dummy_packet));
144 144
145 // Try out the actual conversion (should be successful and allocate new 145 // Try out the actual conversion (should be successful and allocate new
146 // packet and destroy the old one). 146 // packet and destroy the old one).
147 EXPECT_TRUE(converter.ConvertPacket(test_packet.get())); 147 EXPECT_TRUE(converter.ConvertPacket(test_packet.get()));
148 148
149 // Check that the ADTS header frame length matches the packet size 149 // Check that the ADTS header frame length matches the packet size
(...skipping 14 matching lines...) Expand all
164 164
165 // Check that the ADTS header frame length matches the packet size 165 // Check that the ADTS header frame length matches the packet size
166 frame_length = ((second_test_packet->data[3] & 0x03) << 11) | 166 frame_length = ((second_test_packet->data[3] & 0x03) << 11) |
167 ((second_test_packet->data[4] & 0xFF) << 3) | 167 ((second_test_packet->data[4] & 0xFF) << 3) |
168 ((second_test_packet->data[5] & 0xE0) >> 5); 168 ((second_test_packet->data[5] & 0xE0) >> 5);
169 169
170 EXPECT_EQ(frame_length, second_test_packet->size); 170 EXPECT_EQ(frame_length, second_test_packet->size);
171 } 171 }
172 172
173 } // namespace media 173 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698