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

Side by Side Diff: source/libvpx/vpxenc.c

Issue 232133009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vpxdec.c ('k') | source/libvpx/y4minput.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return 0; 116 return 0;
117 } 117 }
118 118
119 int fourcc_is_ivf(const char detect[4]) { 119 int fourcc_is_ivf(const char detect[4]) {
120 if (memcmp(detect, "DKIF", 4) == 0) { 120 if (memcmp(detect, "DKIF", 4) == 0) {
121 return 1; 121 return 1;
122 } 122 }
123 return 0; 123 return 0;
124 } 124 }
125 125
126 #if CONFIG_WEBM_IO
126 /* Murmur hash derived from public domain reference implementation at 127 /* Murmur hash derived from public domain reference implementation at
127 * http:// sites.google.com/site/murmurhash/ 128 * http:// sites.google.com/site/murmurhash/
128 */ 129 */
129 static unsigned int murmur(const void *key, int len, unsigned int seed) { 130 static unsigned int murmur(const void *key, int len, unsigned int seed) {
130 const unsigned int m = 0x5bd1e995; 131 const unsigned int m = 0x5bd1e995;
131 const int r = 24; 132 const int r = 24;
132 133
133 unsigned int h = seed ^ len; 134 unsigned int h = seed ^ len;
134 135
135 const unsigned char *data = (const unsigned char *)key; 136 const unsigned char *data = (const unsigned char *)key;
(...skipping 26 matching lines...) Expand all
162 h ^= data[0]; 163 h ^= data[0];
163 h *= m; 164 h *= m;
164 }; 165 };
165 166
166 h ^= h >> 13; 167 h ^= h >> 13;
167 h *= m; 168 h *= m;
168 h ^= h >> 15; 169 h ^= h >> 15;
169 170
170 return h; 171 return h;
171 } 172 }
172 173 #endif // CONFIG_WEBM_IO
173 174
174 static const arg_def_t debugmode = ARG_DEF("D", "debug", 0, 175 static const arg_def_t debugmode = ARG_DEF("D", "debug", 0,
175 "Debug mode (makes output determinist ic)"); 176 "Debug mode (makes output determinist ic)");
176 static const arg_def_t outputfile = ARG_DEF("o", "output", 1, 177 static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
177 "Output filename"); 178 "Output filename");
178 static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0, 179 static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0,
179 "Input file is YV12 "); 180 "Input file is YV12 ");
180 static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0, 181 static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0,
181 "Input file is I420 (default)"); 182 "Input file is I420 (default)");
182 static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, 183 static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1,
(...skipping 28 matching lines...) Expand all
211 {"fatal", TEST_DECODE_FATAL}, 212 {"fatal", TEST_DECODE_FATAL},
212 {"warn", TEST_DECODE_WARN}, 213 {"warn", TEST_DECODE_WARN},
213 {NULL, 0} 214 {NULL, 0}
214 }; 215 };
215 static const arg_def_t recontest = ARG_DEF_ENUM(NULL, "test-decode", 1, 216 static const arg_def_t recontest = ARG_DEF_ENUM(NULL, "test-decode", 1,
216 "Test encode/decode mismatch", 217 "Test encode/decode mismatch",
217 test_decode_enum); 218 test_decode_enum);
218 static const arg_def_t framerate = ARG_DEF(NULL, "fps", 1, 219 static const arg_def_t framerate = ARG_DEF(NULL, "fps", 1,
219 "Stream frame rate (rate/scale )"); 220 "Stream frame rate (rate/scale )");
220 static const arg_def_t use_ivf = ARG_DEF(NULL, "ivf", 0, 221 static const arg_def_t use_ivf = ARG_DEF(NULL, "ivf", 0,
221 "Output IVF (default is WebM)" ); 222 "Output IVF (default is WebM i f WebM IO is enabled)");
222 static const arg_def_t out_part = ARG_DEF("P", "output-partitions", 0, 223 static const arg_def_t out_part = ARG_DEF("P", "output-partitions", 0,
223 "Makes encoder output partitions. Requ ires IVF output!"); 224 "Makes encoder output partitions. Requ ires IVF output!");
224 static const arg_def_t q_hist_n = ARG_DEF(NULL, "q-hist", 1, 225 static const arg_def_t q_hist_n = ARG_DEF(NULL, "q-hist", 1,
225 "Show quantizer histogram (n-b uckets)"); 226 "Show quantizer histogram (n-b uckets)");
226 static const arg_def_t rate_hist_n = ARG_DEF(NULL, "rate-hist", 1, 227 static const arg_def_t rate_hist_n = ARG_DEF(NULL, "rate-hist", 1,
227 "Show rate histogram (n-buc kets)"); 228 "Show rate histogram (n-buc kets)");
228 static const arg_def_t disable_warnings = 229 static const arg_def_t disable_warnings =
229 ARG_DEF(NULL, "disable-warnings", 0, 230 ARG_DEF(NULL, "disable-warnings", 0,
230 "Disable warnings about potentially incorrect encode settings."); 231 "Disable warnings about potentially incorrect encode settings.");
231 static const arg_def_t disable_warning_prompt = 232 static const arg_def_t disable_warning_prompt =
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 #if CONFIG_VP9_ENCODER 393 #if CONFIG_VP9_ENCODER
393 static const arg_def_t tile_cols = 394 static const arg_def_t tile_cols =
394 ARG_DEF(NULL, "tile-columns", 1, "Number of tile columns to use, log2"); 395 ARG_DEF(NULL, "tile-columns", 1, "Number of tile columns to use, log2");
395 static const arg_def_t tile_rows = 396 static const arg_def_t tile_rows =
396 ARG_DEF(NULL, "tile-rows", 1, "Number of tile rows to use, log2"); 397 ARG_DEF(NULL, "tile-rows", 1, "Number of tile rows to use, log2");
397 static const arg_def_t lossless = ARG_DEF(NULL, "lossless", 1, "Lossless mode"); 398 static const arg_def_t lossless = ARG_DEF(NULL, "lossless", 1, "Lossless mode");
398 static const arg_def_t frame_parallel_decoding = ARG_DEF( 399 static const arg_def_t frame_parallel_decoding = ARG_DEF(
399 NULL, "frame-parallel", 1, "Enable frame parallel decodability features"); 400 NULL, "frame-parallel", 1, "Enable frame parallel decodability features");
400 static const arg_def_t aq_mode = ARG_DEF( 401 static const arg_def_t aq_mode = ARG_DEF(
401 NULL, "aq-mode", 1, 402 NULL, "aq-mode", 1,
402 "Adaptive q mode (0: off (by default), 1: variance 2: complexity)"); 403 "Adaptive q mode (0: off (by default), 1: variance 2: complexity, "
404 "3: cyclic refresh)");
405 static const arg_def_t frame_periodic_boost = ARG_DEF(
406 NULL, "frame_boost", 1,
407 "Enable frame periodic boost (0: off (by default), 1: on)");
403 408
404 static const arg_def_t *vp9_args[] = { 409 static const arg_def_t *vp9_args[] = {
405 &cpu_used, &auto_altref, &noise_sens, &sharpness, &static_thresh, 410 &cpu_used, &auto_altref, &noise_sens, &sharpness, &static_thresh,
406 &tile_cols, &tile_rows, &arnr_maxframes, &arnr_strength, &arnr_type, 411 &tile_cols, &tile_rows, &arnr_maxframes, &arnr_strength, &arnr_type,
407 &tune_ssim, &cq_level, &max_intra_rate_pct, &lossless, 412 &tune_ssim, &cq_level, &max_intra_rate_pct, &lossless,
408 &frame_parallel_decoding, &aq_mode, 413 &frame_parallel_decoding, &aq_mode, &frame_periodic_boost,
409 NULL 414 NULL
410 }; 415 };
411 static const int vp9_arg_ctrl_map[] = { 416 static const int vp9_arg_ctrl_map[] = {
412 VP8E_SET_CPUUSED, VP8E_SET_ENABLEAUTOALTREF, 417 VP8E_SET_CPUUSED, VP8E_SET_ENABLEAUTOALTREF,
413 VP8E_SET_NOISE_SENSITIVITY, VP8E_SET_SHARPNESS, VP8E_SET_STATIC_THRESHOLD, 418 VP8E_SET_NOISE_SENSITIVITY, VP8E_SET_SHARPNESS, VP8E_SET_STATIC_THRESHOLD,
414 VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS, 419 VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS,
415 VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE, 420 VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE,
416 VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT, 421 VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT,
417 VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE, 422 VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE,
423 VP9E_SET_FRAME_PERIODIC_BOOST,
418 0 424 0
419 }; 425 };
420 #endif 426 #endif
421 427
422 static const arg_def_t *no_args[] = { NULL }; 428 static const arg_def_t *no_args[] = { NULL };
423 429
424 void usage_exit() { 430 void usage_exit() {
425 int i; 431 int i;
426 432
427 fprintf(stderr, "Usage: %s <options> -o dst_filename src_filename \n", 433 fprintf(stderr, "Usage: %s <options> -o dst_filename src_filename \n",
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 833
828 /* Never use the library's default resolution, require it be parsed 834 /* Never use the library's default resolution, require it be parsed
829 * from the file or set on the command line. 835 * from the file or set on the command line.
830 */ 836 */
831 stream->config.cfg.g_w = 0; 837 stream->config.cfg.g_w = 0;
832 stream->config.cfg.g_h = 0; 838 stream->config.cfg.g_h = 0;
833 839
834 /* Initialize remaining stream parameters */ 840 /* Initialize remaining stream parameters */
835 stream->config.stereo_fmt = STEREO_FORMAT_MONO; 841 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
836 stream->config.write_webm = 1; 842 stream->config.write_webm = 1;
843 #if CONFIG_WEBM_IO
837 stream->ebml.last_pts_ms = -1; 844 stream->ebml.last_pts_ms = -1;
845 #endif
838 846
839 /* Allows removal of the application version from the EBML tags */ 847 /* Allows removal of the application version from the EBML tags */
840 stream->ebml.debug = global->debug; 848 stream->ebml.debug = global->debug;
841 849
842 /* Default lag_in_frames is 0 in realtime mode */ 850 /* Default lag_in_frames is 0 in realtime mode */
843 if (global->deadline == VPX_DL_REALTIME) 851 if (global->deadline == VPX_DL_REALTIME)
844 stream->config.cfg.g_lag_in_frames = 0; 852 stream->config.cfg.g_lag_in_frames = 0;
845 } 853 }
846 854
847 /* Output files must be specified for each stream */ 855 /* Output files must be specified for each stream */
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 return; 1144 return;
1137 1145
1138 stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout); 1146 stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout);
1139 1147
1140 if (!stream->file) 1148 if (!stream->file)
1141 fatal("Failed to open output file"); 1149 fatal("Failed to open output file");
1142 1150
1143 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR)) 1151 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1144 fatal("WebM output to pipes not supported."); 1152 fatal("WebM output to pipes not supported.");
1145 1153
1154 #if CONFIG_WEBM_IO
1146 if (stream->config.write_webm) { 1155 if (stream->config.write_webm) {
1147 stream->ebml.stream = stream->file; 1156 stream->ebml.stream = stream->file;
1148 write_webm_file_header(&stream->ebml, cfg, 1157 write_webm_file_header(&stream->ebml, cfg,
1149 &global->framerate, 1158 &global->framerate,
1150 stream->config.stereo_fmt, 1159 stream->config.stereo_fmt,
1151 global->codec->fourcc); 1160 global->codec->fourcc);
1152 } else { 1161 }
1162 #endif
1163
1164 if (!stream->config.write_webm) {
1153 ivf_write_file_header(stream->file, cfg, global->codec->fourcc, 0); 1165 ivf_write_file_header(stream->file, cfg, global->codec->fourcc, 0);
1154 } 1166 }
1155 } 1167 }
1156 1168
1157 1169
1158 static void close_output_file(struct stream_state *stream, 1170 static void close_output_file(struct stream_state *stream,
1159 unsigned int fourcc) { 1171 unsigned int fourcc) {
1160 const struct vpx_codec_enc_cfg *const cfg = &stream->config.cfg; 1172 const struct vpx_codec_enc_cfg *const cfg = &stream->config.cfg;
1161 1173
1162 if (cfg->g_pass == VPX_RC_FIRST_PASS) 1174 if (cfg->g_pass == VPX_RC_FIRST_PASS)
1163 return; 1175 return;
1164 1176
1177 #if CONFIG_WEBM_IO
1165 if (stream->config.write_webm) { 1178 if (stream->config.write_webm) {
1166 write_webm_file_footer(&stream->ebml, stream->hash); 1179 write_webm_file_footer(&stream->ebml, stream->hash);
1167 free(stream->ebml.cue_list); 1180 free(stream->ebml.cue_list);
1168 stream->ebml.cue_list = NULL; 1181 stream->ebml.cue_list = NULL;
1169 } else { 1182 }
1183 #endif
1184
1185 if (!stream->config.write_webm) {
1170 if (!fseek(stream->file, 0, SEEK_SET)) 1186 if (!fseek(stream->file, 0, SEEK_SET))
1171 ivf_write_file_header(stream->file, &stream->config.cfg, 1187 ivf_write_file_header(stream->file, &stream->config.cfg,
1172 fourcc, 1188 fourcc,
1173 stream->frames_out); 1189 stream->frames_out);
1174 } 1190 }
1175 1191
1176 fclose(stream->file); 1192 fclose(stream->file);
1177 } 1193 }
1178 1194
1179 1195
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 1325
1310 switch (pkt->kind) { 1326 switch (pkt->kind) {
1311 case VPX_CODEC_CX_FRAME_PKT: 1327 case VPX_CODEC_CX_FRAME_PKT:
1312 if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) { 1328 if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
1313 stream->frames_out++; 1329 stream->frames_out++;
1314 } 1330 }
1315 if (!global->quiet) 1331 if (!global->quiet)
1316 fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz); 1332 fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz);
1317 1333
1318 update_rate_histogram(stream->rate_hist, cfg, pkt); 1334 update_rate_histogram(stream->rate_hist, cfg, pkt);
1335 #if CONFIG_WEBM_IO
1319 if (stream->config.write_webm) { 1336 if (stream->config.write_webm) {
1320 /* Update the hash */ 1337 /* Update the hash */
1321 if (!stream->ebml.debug) 1338 if (!stream->ebml.debug)
1322 stream->hash = murmur(pkt->data.frame.buf, 1339 stream->hash = murmur(pkt->data.frame.buf,
1323 (int)pkt->data.frame.sz, 1340 (int)pkt->data.frame.sz,
1324 stream->hash); 1341 stream->hash);
1325 1342
1326 write_webm_block(&stream->ebml, cfg, pkt); 1343 write_webm_block(&stream->ebml, cfg, pkt);
1327 } else { 1344 }
1345 #endif
1346 if (!stream->config.write_webm) {
1328 if (pkt->data.frame.partition_id <= 0) { 1347 if (pkt->data.frame.partition_id <= 0) {
1329 ivf_header_pos = ftello(stream->file); 1348 ivf_header_pos = ftello(stream->file);
1330 fsize = pkt->data.frame.sz; 1349 fsize = pkt->data.frame.sz;
1331 1350
1332 ivf_write_frame_header(stream->file, pkt->data.frame.pts, fsize); 1351 ivf_write_frame_header(stream->file, pkt->data.frame.pts, fsize);
1333 } else { 1352 } else {
1334 fsize += pkt->data.frame.sz; 1353 fsize += pkt->data.frame.sz;
1335 1354
1336 if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) { 1355 if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
1337 off_t currpos = ftello(stream->file); 1356 off_t currpos = ftello(stream->file);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 int64_t mins; 1496 int64_t mins;
1478 int64_t secs; 1497 int64_t secs;
1479 1498
1480 if (etl >= 0) { 1499 if (etl >= 0) {
1481 hours = etl / 3600; 1500 hours = etl / 3600;
1482 etl -= hours * 3600; 1501 etl -= hours * 3600;
1483 mins = etl / 60; 1502 mins = etl / 60;
1484 etl -= mins * 60; 1503 etl -= mins * 60;
1485 secs = etl; 1504 secs = etl;
1486 1505
1487 fprintf(stderr, "[%3s %2"PRId64":%02"PRId64": % 02"PRId64"] ", 1506 fprintf(stderr, "[%3s %2"PRId64":%02"PRId64":%02"PRId64"] ",
1488 label, hours, mins, secs); 1507 label, hours, mins, secs);
1489 } else { 1508 } else {
1490 fprintf(stderr, "[%3s unknown] ", label); 1509 fprintf(stderr, "[%3s unknown] ", label);
1491 } 1510 }
1492 } 1511 }
1493 1512
1494 1513
1495 int main(int argc, const char **argv_) { 1514 int main(int argc, const char **argv_) {
1496 int pass; 1515 int pass;
1497 vpx_image_t raw; 1516 vpx_image_t raw;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 /* Ensure that --passes and --pass are consistent. If --pass is set and 1606 /* Ensure that --passes and --pass are consistent. If --pass is set and
1588 * --passes=2, ensure --fpf was set. 1607 * --passes=2, ensure --fpf was set.
1589 */ 1608 */
1590 if (global.pass && global.passes == 2) 1609 if (global.pass && global.passes == 2)
1591 FOREACH_STREAM( { 1610 FOREACH_STREAM( {
1592 if (!stream->config.stats_fn) 1611 if (!stream->config.stats_fn)
1593 die("Stream %d: Must specify --fpf when --pass=%d" 1612 die("Stream %d: Must specify --fpf when --pass=%d"
1594 " and --passes=2\n", stream->index, global.pass); 1613 " and --passes=2\n", stream->index, global.pass);
1595 }); 1614 });
1596 1615
1616 #if !CONFIG_WEBM_IO
1617 FOREACH_STREAM({
1618 stream->config.write_webm = 0;
1619 warn("vpxenc was compiled without WebM container support."
1620 "Producing IVF output");
1621 });
1622 #endif
1623
1597 /* Use the frame rate from the file only if none was specified 1624 /* Use the frame rate from the file only if none was specified
1598 * on the command-line. 1625 * on the command-line.
1599 */ 1626 */
1600 if (!global.have_framerate) { 1627 if (!global.have_framerate) {
1601 global.framerate.num = input.framerate.numerator; 1628 global.framerate.num = input.framerate.numerator;
1602 global.framerate.den = input.framerate.denominator; 1629 global.framerate.den = input.framerate.denominator;
1603 } 1630 }
1604 1631
1605 FOREACH_STREAM(set_default_kf_interval(stream, &global)); 1632 FOREACH_STREAM(set_default_kf_interval(stream, &global));
1606 1633
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 } 1806 }
1780 fclose(f); 1807 fclose(f);
1781 }); 1808 });
1782 #endif 1809 #endif
1783 1810
1784 vpx_img_free(&raw); 1811 vpx_img_free(&raw);
1785 free(argv); 1812 free(argv);
1786 free(streams); 1813 free(streams);
1787 return res ? EXIT_FAILURE : EXIT_SUCCESS; 1814 return res ? EXIT_FAILURE : EXIT_SUCCESS;
1788 } 1815 }
OLDNEW
« no previous file with comments | « source/libvpx/vpxdec.c ('k') | source/libvpx/y4minput.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698