Huge Windows utf8 I/O patch.
[platform/upstream/flac.git] / src / metaflac / operations_shorthand_streaminfo.c
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001,2002,2003,2004,2005,2006,2007,2008,2009  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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "options.h"
24 #include "utils.h"
25 #include "FLAC/assert.h"
26 #include "FLAC/metadata.h"
27 #include "share/compat.h"
28 #include <string.h>
29 #include "operations_shorthand.h"
30
31 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)
32 {
33         unsigned i;
34         FLAC__bool ok = true;
35         FLAC__StreamMetadata *block;
36         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
37
38         if(0 == iterator)
39                 die("out of memory allocating iterator");
40
41         FLAC__metadata_iterator_init(iterator, chain);
42
43         block = FLAC__metadata_iterator_get_block(iterator);
44
45         FLAC__ASSERT(0 != block);
46         FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO);
47
48         if(prefix_with_filename)
49                 flac_printf("%s:", filename);
50
51         switch(operation->type) {
52                 case OP__SHOW_MD5SUM:
53                         for(i = 0; i < 16; i++)
54                                 printf("%02x", block->data.stream_info.md5sum[i]);
55                         printf("\n");
56                         break;
57                 case OP__SHOW_MIN_BLOCKSIZE:
58                         printf("%u\n", block->data.stream_info.min_blocksize);
59                         break;
60                 case OP__SHOW_MAX_BLOCKSIZE:
61                         printf("%u\n", block->data.stream_info.max_blocksize);
62                         break;
63                 case OP__SHOW_MIN_FRAMESIZE:
64                         printf("%u\n", block->data.stream_info.min_framesize);
65                         break;
66                 case OP__SHOW_MAX_FRAMESIZE:
67                         printf("%u\n", block->data.stream_info.max_framesize);
68                         break;
69                 case OP__SHOW_SAMPLE_RATE:
70                         printf("%u\n", block->data.stream_info.sample_rate);
71                         break;
72                 case OP__SHOW_CHANNELS:
73                         printf("%u\n", block->data.stream_info.channels);
74                         break;
75                 case OP__SHOW_BPS:
76                         printf("%u\n", block->data.stream_info.bits_per_sample);
77                         break;
78                 case OP__SHOW_TOTAL_SAMPLES:
79                         printf("%" PRIu64 "\n", block->data.stream_info.total_samples);
80                         break;
81                 case OP__SET_MD5SUM:
82                         memcpy(block->data.stream_info.md5sum, operation->argument.streaminfo_md5.value, 16);
83                         *needs_write = true;
84                         break;
85                 case OP__SET_MIN_BLOCKSIZE:
86                         block->data.stream_info.min_blocksize = operation->argument.streaminfo_uint32.value;
87                         *needs_write = true;
88                         break;
89                 case OP__SET_MAX_BLOCKSIZE:
90                         block->data.stream_info.max_blocksize = operation->argument.streaminfo_uint32.value;
91                         *needs_write = true;
92                         break;
93                 case OP__SET_MIN_FRAMESIZE:
94                         block->data.stream_info.min_framesize = operation->argument.streaminfo_uint32.value;
95                         *needs_write = true;
96                         break;
97                 case OP__SET_MAX_FRAMESIZE:
98                         block->data.stream_info.max_framesize = operation->argument.streaminfo_uint32.value;
99                         *needs_write = true;
100                         break;
101                 case OP__SET_SAMPLE_RATE:
102                         block->data.stream_info.sample_rate = operation->argument.streaminfo_uint32.value;
103                         *needs_write = true;
104                         break;
105                 case OP__SET_CHANNELS:
106                         block->data.stream_info.channels = operation->argument.streaminfo_uint32.value;
107                         *needs_write = true;
108                         break;
109                 case OP__SET_BPS:
110                         block->data.stream_info.bits_per_sample = operation->argument.streaminfo_uint32.value;
111                         *needs_write = true;
112                         break;
113                 case OP__SET_TOTAL_SAMPLES:
114                         block->data.stream_info.total_samples = operation->argument.streaminfo_uint64.value;
115                         *needs_write = true;
116                         break;
117                 default:
118                         ok = false;
119                         FLAC__ASSERT(0);
120                         break;
121         };
122
123         FLAC__metadata_iterator_delete(iterator);
124
125         return ok;
126 }