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