• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // container-raw.c - a parser/builder for a container with raw data frame.
4 //
5 // Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 //
7 // Licensed under the terms of the GNU General Public License, version 2.
8 
9 #include "container.h"
10 #include "misc.h"
11 
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 
raw_builder_pre_process(struct container_context * cntr,snd_pcm_format_t * sample_format,unsigned int * samples_per_frame,unsigned int * frames_per_second,uint64_t * byte_count)16 static int raw_builder_pre_process(struct container_context *cntr,
17 				   snd_pcm_format_t *sample_format,
18 				   unsigned int *samples_per_frame,
19 				   unsigned int *frames_per_second,
20 				   uint64_t *byte_count)
21 {
22 	*byte_count = UINT64_MAX;
23 
24 	return 0;
25 }
26 
raw_parser_pre_process(struct container_context * cntr,snd_pcm_format_t * sample_format,unsigned int * samples_per_frame,unsigned int * frames_per_second,uint64_t * byte_count)27 static int raw_parser_pre_process(struct container_context *cntr,
28 				  snd_pcm_format_t *sample_format,
29 				  unsigned int *samples_per_frame,
30 				  unsigned int *frames_per_second,
31 				  uint64_t *byte_count)
32 {
33 	struct stat buf = {0};
34 	int err;
35 
36 	if (cntr->stdio) {
37 		*byte_count = UINT64_MAX;
38 		return 0;
39 	}
40 
41 	err = fstat(cntr->fd, &buf);
42 	if (err < 0)
43 		return err;
44 
45 	*byte_count = buf.st_size;
46 	if (*byte_count == 0)
47 		*byte_count = UINT64_MAX;
48 
49 	return 0;
50 }
51 
52 const struct container_parser container_parser_raw = {
53 	.format = CONTAINER_FORMAT_RAW,
54 	.max_size = UINT64_MAX,
55 	.ops = {
56 		.pre_process = raw_parser_pre_process,
57 	},
58 };
59 
60 const struct container_builder container_builder_raw = {
61 	.format = CONTAINER_FORMAT_RAW,
62 	.max_size = UINT64_MAX,
63 	.ops = {
64 		.pre_process = raw_builder_pre_process,
65 	},
66 };
67