2014-01-24 10:37:15 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
2013-09-18 14:29:30 +00:00
|
|
|
*
|
2014-01-24 10:37:15 +00:00
|
|
|
* Copyright (C) 2013-2014 Tampere University of Technology and others (see
|
|
|
|
* COPYING file).
|
|
|
|
*
|
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as published
|
|
|
|
* by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Kvazaar is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* \file
|
2012-05-30 12:10:23 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-18 09:16:03 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-05-30 12:10:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
/**
|
|
|
|
* \brief Allocate memory for config object
|
|
|
|
* \return pointer to allocated memory
|
|
|
|
*/
|
|
|
|
config *config_alloc()
|
2012-05-30 12:10:23 +00:00
|
|
|
{
|
2013-09-19 08:28:58 +00:00
|
|
|
config *cfg = (config *)malloc(sizeof(config));
|
2014-01-31 15:30:27 +00:00
|
|
|
if (!cfg) {
|
|
|
|
fprintf(stderr, "Failed to allocate a config object!\n");
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:10:23 +00:00
|
|
|
memset(cfg, 0, sizeof(config));
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
/**
|
|
|
|
* \brief Initialize config structure
|
|
|
|
* \param cfg config object
|
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
|
|
|
int config_init(config *cfg)
|
2012-05-30 12:10:23 +00:00
|
|
|
{
|
|
|
|
cfg->input = NULL;
|
|
|
|
cfg->output = NULL;
|
|
|
|
cfg->debug = NULL;
|
|
|
|
cfg->frames = 0;
|
2012-05-30 12:26:39 +00:00
|
|
|
cfg->width = 320;
|
|
|
|
cfg->height = 240;
|
2014-01-27 13:02:07 +00:00
|
|
|
cfg->qp = 32;
|
2014-01-31 08:23:56 +00:00
|
|
|
cfg->intra_period = 0;
|
2012-05-30 12:10:23 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
/**
|
|
|
|
* \brief Free memory allocated to the config
|
|
|
|
* \param cfg config object
|
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
|
|
|
int config_destroy(config *cfg)
|
2012-05-30 12:10:23 +00:00
|
|
|
{
|
2013-09-18 11:50:43 +00:00
|
|
|
FREE_POINTER(cfg->input);
|
|
|
|
FREE_POINTER(cfg->output);
|
2012-05-30 12:10:23 +00:00
|
|
|
free(cfg);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-31 15:24:04 +00:00
|
|
|
/**
|
|
|
|
* \brief Allocates memory space for a string, and copies it
|
|
|
|
* \param char * string to copy
|
|
|
|
* \return a pointer to the copied string on success, null on failure
|
|
|
|
*/
|
|
|
|
char *copy_string(char *string)
|
|
|
|
{
|
|
|
|
// Allocate +1 for \0
|
|
|
|
char *allocated_string = (char *)malloc(strlen(string) + 1);
|
|
|
|
if (!allocated_string) {
|
|
|
|
fprintf(stderr, "Failed to allocate a string!\n");
|
|
|
|
return allocated_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the string to the new buffer
|
|
|
|
memcpy(allocated_string, string, strlen(string) + 1);
|
|
|
|
|
|
|
|
return allocated_string;
|
|
|
|
}
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
/**
|
|
|
|
* \brief Read configuration options from argv to the config struct
|
|
|
|
* \param cfg config object
|
|
|
|
* \param argc argument count
|
|
|
|
* \param argv argument list
|
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
|
|
|
int config_read(config *cfg,int argc, char *argv[])
|
2012-05-30 12:10:23 +00:00
|
|
|
{
|
|
|
|
uint32_t pos = 0;
|
|
|
|
int arg = 1;
|
|
|
|
char option = 0;
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
while(arg < argc && pos < strlen(argv[arg])) {
|
|
|
|
// Check for an option
|
|
|
|
if(argv[arg][0] == '-' && strlen(argv[arg]) > 1) {
|
|
|
|
// Second letter of the argument is the option we want to use
|
2012-05-30 12:10:23 +00:00
|
|
|
option = argv[arg][1];
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
// Point to the next argument
|
2012-05-30 12:10:23 +00:00
|
|
|
arg++;
|
2013-09-19 08:28:58 +00:00
|
|
|
switch(option) {
|
|
|
|
case 'i': // Input
|
2014-01-31 15:24:04 +00:00
|
|
|
cfg->input = copy_string(argv[arg]);
|
2012-05-30 12:10:23 +00:00
|
|
|
break;
|
2013-09-19 08:28:58 +00:00
|
|
|
case 'o': // Output
|
2014-01-31 15:24:04 +00:00
|
|
|
cfg->output = copy_string(argv[arg]);
|
2012-05-30 12:10:23 +00:00
|
|
|
break;
|
2013-09-19 08:28:58 +00:00
|
|
|
case 'd': // Debug
|
2014-01-31 15:24:04 +00:00
|
|
|
cfg->debug = copy_string(argv[arg]);
|
2012-05-30 12:10:23 +00:00
|
|
|
break;
|
2013-09-19 08:28:58 +00:00
|
|
|
case 'w': // width
|
2012-05-30 12:10:23 +00:00
|
|
|
cfg->width = atoi(argv[arg]);
|
|
|
|
break;
|
2013-09-19 08:28:58 +00:00
|
|
|
case 'h': // height
|
2012-05-30 12:10:23 +00:00
|
|
|
cfg->height = atoi(argv[arg]);
|
|
|
|
break;
|
2013-09-19 08:28:58 +00:00
|
|
|
case 'n': // number of frames to encode
|
2012-05-30 12:10:23 +00:00
|
|
|
cfg->frames = atoi(argv[arg]);
|
|
|
|
break;
|
2014-01-27 13:02:07 +00:00
|
|
|
case 'q': // QP
|
|
|
|
cfg->qp = atoi(argv[arg]);
|
|
|
|
break;
|
2014-01-31 08:23:56 +00:00
|
|
|
case 'p': // Intra period
|
|
|
|
cfg->intra_period = atoi(argv[arg]);
|
|
|
|
break;
|
2012-05-30 12:10:23 +00:00
|
|
|
default:
|
2013-09-19 08:28:58 +00:00
|
|
|
// Unknown command, print error message and ignore
|
2012-05-30 12:10:23 +00:00
|
|
|
fprintf(stderr, "%c is not a known option\r\n", option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 08:28:58 +00:00
|
|
|
// Next argument
|
2012-05-30 12:10:23 +00:00
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
|
2013-09-19 08:28:58 +00:00
|
|
|
// Check that the required files were defined
|
|
|
|
if(cfg->input == NULL || cfg->output == NULL) return 0;
|
2012-05-30 12:10:23 +00:00
|
|
|
|
|
|
|
return 1;
|
2014-02-03 14:32:54 +00:00
|
|
|
}
|