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
16static int raw_builder_pre_process(struct container_context *cntr ATTRIBUTE_UNUSED,
17				   snd_pcm_format_t *format ATTRIBUTE_UNUSED,
18				   unsigned int *samples_per_frame ATTRIBUTE_UNUSED,
19				   unsigned int *frames_per_second ATTRIBUTE_UNUSED,
20				   uint64_t *byte_count)
21{
22	*byte_count = UINT64_MAX;
23
24	return 0;
25}
26
27static int raw_parser_pre_process(struct container_context *cntr,
28				  snd_pcm_format_t *format ATTRIBUTE_UNUSED,
29				  unsigned int *samples_per_frame ATTRIBUTE_UNUSED,
30				  unsigned int *frames_per_second ATTRIBUTE_UNUSED,
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
52const 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
60const 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