operations_shorthand_streaminfo.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:4k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* metaflac - Command-line FLAC metadata editor
  2.  * Copyright (C) 2001,2002,2003,2004,2005  Josh Coalson
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  */
  18. #include "options.h"
  19. #include "utils.h"
  20. #include "FLAC/assert.h"
  21. #include "FLAC/metadata.h"
  22. #include <string.h>
  23. FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
  24. {
  25. unsigned i;
  26. FLAC__bool ok = true;
  27. FLAC__StreamMetadata *block;
  28. FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
  29. if(0 == iterator)
  30. die("out of memory allocating iterator");
  31. FLAC__metadata_iterator_init(iterator, chain);
  32. block = FLAC__metadata_iterator_get_block(iterator);
  33. FLAC__ASSERT(0 != block);
  34. FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO);
  35. if(prefix_with_filename)
  36. printf("%s:", filename);
  37. switch(operation->type) {
  38. case OP__SHOW_MD5SUM:
  39. for(i = 0; i < 16; i++)
  40. printf("%02x", block->data.stream_info.md5sum[i]);
  41. printf("n");
  42. break;
  43. case OP__SHOW_MIN_BLOCKSIZE:
  44. printf("%un", block->data.stream_info.min_blocksize);
  45. break;
  46. case OP__SHOW_MAX_BLOCKSIZE:
  47. printf("%un", block->data.stream_info.max_blocksize);
  48. break;
  49. case OP__SHOW_MIN_FRAMESIZE:
  50. printf("%un", block->data.stream_info.min_framesize);
  51. break;
  52. case OP__SHOW_MAX_FRAMESIZE:
  53. printf("%un", block->data.stream_info.max_framesize);
  54. break;
  55. case OP__SHOW_SAMPLE_RATE:
  56. printf("%un", block->data.stream_info.sample_rate);
  57. break;
  58. case OP__SHOW_CHANNELS:
  59. printf("%un", block->data.stream_info.channels);
  60. break;
  61. case OP__SHOW_BPS:
  62. printf("%un", block->data.stream_info.bits_per_sample);
  63. break;
  64. case OP__SHOW_TOTAL_SAMPLES:
  65. #ifdef _MSC_VER
  66. printf("%I64un", block->data.stream_info.total_samples);
  67. #else
  68. printf("%llun", block->data.stream_info.total_samples);
  69. #endif
  70. break;
  71. case OP__SET_MD5SUM:
  72. memcpy(block->data.stream_info.md5sum, operation->argument.streaminfo_md5.value, 16);
  73. *needs_write = true;
  74. break;
  75. case OP__SET_MIN_BLOCKSIZE:
  76. block->data.stream_info.min_blocksize = operation->argument.streaminfo_uint32.value;
  77. *needs_write = true;
  78. break;
  79. case OP__SET_MAX_BLOCKSIZE:
  80. block->data.stream_info.max_blocksize = operation->argument.streaminfo_uint32.value;
  81. *needs_write = true;
  82. break;
  83. case OP__SET_MIN_FRAMESIZE:
  84. block->data.stream_info.min_framesize = operation->argument.streaminfo_uint32.value;
  85. *needs_write = true;
  86. break;
  87. case OP__SET_MAX_FRAMESIZE:
  88. block->data.stream_info.max_framesize = operation->argument.streaminfo_uint32.value;
  89. *needs_write = true;
  90. break;
  91. case OP__SET_SAMPLE_RATE:
  92. block->data.stream_info.sample_rate = operation->argument.streaminfo_uint32.value;
  93. *needs_write = true;
  94. break;
  95. case OP__SET_CHANNELS:
  96. block->data.stream_info.channels = operation->argument.streaminfo_uint32.value;
  97. *needs_write = true;
  98. break;
  99. case OP__SET_BPS:
  100. block->data.stream_info.bits_per_sample = operation->argument.streaminfo_uint32.value;
  101. *needs_write = true;
  102. break;
  103. case OP__SET_TOTAL_SAMPLES:
  104. block->data.stream_info.total_samples = operation->argument.streaminfo_uint64.value;
  105. *needs_write = true;
  106. break;
  107. default:
  108. ok = false;
  109. FLAC__ASSERT(0);
  110. break;
  111. };
  112. FLAC__metadata_iterator_delete(iterator);
  113. return ok;
  114. }