2016-07-13 16:29:55 +00:00
|
|
|
/* Spa FFMpeg Encoder
|
|
|
|
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2016-10-07 11:14:32 +00:00
|
|
|
#include <spa/log.h>
|
2017-03-24 10:40:58 +00:00
|
|
|
#include <spa/type-map.h>
|
2016-07-13 16:29:55 +00:00
|
|
|
#include <spa/node.h>
|
2017-03-21 15:50:44 +00:00
|
|
|
#include <spa/video/format-utils.h>
|
2016-11-03 18:41:53 +00:00
|
|
|
#include <lib/props.h>
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
#define IS_VALID_PORT(this,d,id) ((id) == 0)
|
2016-07-13 16:29:55 +00:00
|
|
|
#define MAX_BUFFERS 32
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct buffer {
|
|
|
|
struct spa_buffer buffer;
|
|
|
|
struct spa_meta metas[1];
|
|
|
|
struct spa_meta_header header;
|
|
|
|
struct spa_data datas[1];
|
|
|
|
struct spa_buffer *imported;
|
2016-07-13 16:29:55 +00:00
|
|
|
bool outstanding;
|
2017-05-25 11:28:15 +00:00
|
|
|
struct buffer *next;
|
2016-07-13 16:29:55 +00:00
|
|
|
};
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct port {
|
2017-02-28 09:48:53 +00:00
|
|
|
bool have_format;
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_video_info current_format;
|
2016-07-13 16:29:55 +00:00
|
|
|
bool have_buffers;
|
2017-05-25 11:28:15 +00:00
|
|
|
struct buffer buffers[MAX_BUFFERS];
|
|
|
|
struct spa_port_info info;
|
|
|
|
struct spa_port_io *io;
|
|
|
|
};
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct type {
|
2016-10-07 11:14:32 +00:00
|
|
|
uint32_t node;
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_type_media_type media_type;
|
|
|
|
struct spa_type_media_subtype media_subtype;
|
|
|
|
struct spa_type_format_video format_video;
|
|
|
|
struct spa_type_command_node command_node;
|
|
|
|
};
|
2017-03-24 10:40:58 +00:00
|
|
|
|
|
|
|
static inline void
|
2017-05-25 11:28:15 +00:00
|
|
|
init_type (struct type *type, struct spa_type_map *map)
|
2017-03-24 10:40:58 +00:00
|
|
|
{
|
|
|
|
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
|
|
|
spa_type_media_type_map (map, &type->media_type);
|
|
|
|
spa_type_media_subtype_map (map, &type->media_subtype);
|
2017-03-24 17:11:11 +00:00
|
|
|
spa_type_format_video_map (map, &type->format_video);
|
2017-03-24 10:40:58 +00:00
|
|
|
spa_type_command_node_map (map, &type->command_node);
|
|
|
|
}
|
2016-10-07 11:14:32 +00:00
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl {
|
|
|
|
struct spa_handle handle;
|
|
|
|
struct spa_node node;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct type type;
|
|
|
|
struct spa_type_map *map;
|
|
|
|
struct spa_log *log;
|
2016-10-07 11:14:32 +00:00
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_node_callbacks callbacks;
|
2016-07-13 16:29:55 +00:00
|
|
|
void *user_data;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
struct port in_ports[1];
|
|
|
|
struct port out_ports[1];
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-04-08 18:33:54 +00:00
|
|
|
bool started;
|
2016-07-13 16:29:55 +00:00
|
|
|
};
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_get_props (struct spa_node *node,
|
|
|
|
struct spa_props **props)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-02-28 09:48:53 +00:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-07-13 16:29:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_set_props (struct spa_node *node,
|
|
|
|
const struct spa_props *props)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-02-28 09:48:53 +00:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-07-13 16:29:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_send_command (struct spa_node *node,
|
|
|
|
struct spa_command *command)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL || command == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2017-03-24 10:40:58 +00:00
|
|
|
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
2017-04-08 18:33:54 +00:00
|
|
|
this->started = true;
|
2017-03-22 09:04:24 +00:00
|
|
|
}
|
2017-03-24 10:40:58 +00:00
|
|
|
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
2017-04-08 18:33:54 +00:00
|
|
|
this->started = false;
|
2016-07-13 16:29:55 +00:00
|
|
|
}
|
2017-03-22 09:04:24 +00:00
|
|
|
else
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_set_callbacks (struct spa_node *node,
|
|
|
|
const struct spa_node_callbacks *callbacks,
|
2017-05-11 08:29:20 +00:00
|
|
|
size_t callbacks_size,
|
|
|
|
void *user_data)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2017-05-11 08:29:20 +00:00
|
|
|
this->callbacks = *callbacks;
|
2016-07-13 16:29:55 +00:00
|
|
|
this->user_data = user_data;
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_get_n_ports (struct spa_node *node,
|
2017-03-07 10:56:43 +00:00
|
|
|
uint32_t *n_input_ports,
|
|
|
|
uint32_t *max_input_ports,
|
|
|
|
uint32_t *n_output_ports,
|
|
|
|
uint32_t *max_output_ports)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
|
|
if (n_input_ports)
|
|
|
|
*n_input_ports = 1;
|
|
|
|
if (n_output_ports)
|
|
|
|
*n_output_ports = 1;
|
|
|
|
if (max_input_ports)
|
|
|
|
*max_input_ports = 1;
|
|
|
|
if (max_output_ports)
|
|
|
|
*max_output_ports = 1;
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_get_port_ids (struct spa_node *node,
|
2017-03-07 10:56:43 +00:00
|
|
|
uint32_t n_input_ports,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t *input_ids,
|
2017-03-07 10:56:43 +00:00
|
|
|
uint32_t n_output_ports,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t *output_ids)
|
|
|
|
{
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2016-09-05 14:23:40 +00:00
|
|
|
if (n_input_ports > 0 && input_ids != NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
input_ids[0] = 0;
|
2016-09-05 14:23:40 +00:00
|
|
|
if (n_output_ports > 0 && output_ids != NULL)
|
2016-10-04 13:56:33 +00:00
|
|
|
output_ids[0] = 0;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_add_port (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2016-07-30 18:35:34 +00:00
|
|
|
uint32_t port_id)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_remove_port (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t port_id)
|
|
|
|
{
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_enum_formats (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t port_id,
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_format **format,
|
|
|
|
const struct spa_format *filter,
|
2017-03-07 10:56:43 +00:00
|
|
|
uint32_t index)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
//struct impl *this;
|
|
|
|
//struct port *port;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL || format == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
//this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
if (!IS_VALID_PORT (this, direction, port_id))
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
2017-03-17 10:58:09 +00:00
|
|
|
//port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
2016-07-15 16:22:29 +00:00
|
|
|
|
2016-07-13 16:29:55 +00:00
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
}
|
2017-02-24 08:28:18 +00:00
|
|
|
*format = NULL;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_set_format (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2017-05-11 08:29:20 +00:00
|
|
|
uint32_t port_id,
|
|
|
|
uint32_t flags,
|
2017-05-25 11:28:15 +00:00
|
|
|
const struct spa_format *format)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
|
|
|
struct port *port;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL || format == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
if (!IS_VALID_PORT (this, direction, port_id))
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
if (format == NULL) {
|
2017-02-28 09:48:53 +00:00
|
|
|
port->have_format = false;
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_OK;
|
2017-03-24 17:11:11 +00:00
|
|
|
} else {
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format),
|
|
|
|
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-03-24 17:11:11 +00:00
|
|
|
if (info.media_type != this->type.media_type.video &&
|
|
|
|
info.media_subtype != this->type.media_subtype.raw)
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-03-24 17:11:11 +00:00
|
|
|
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
2017-02-24 08:28:18 +00:00
|
|
|
|
2017-03-24 17:11:11 +00:00
|
|
|
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
|
|
|
port->current_format = info;
|
|
|
|
port->have_format = true;
|
|
|
|
}
|
2016-07-13 16:29:55 +00:00
|
|
|
}
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_get_format (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t port_id,
|
2017-05-25 11:28:15 +00:00
|
|
|
const struct spa_format **format)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
|
|
|
struct port *port;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL || format == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
if (!IS_VALID_PORT (this, direction, port_id))
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-02-28 09:48:53 +00:00
|
|
|
if (!port->have_format)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
2017-02-28 09:48:53 +00:00
|
|
|
*format = NULL;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_get_info (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t port_id,
|
2017-05-25 11:28:15 +00:00
|
|
|
const struct spa_port_info **info)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
|
|
|
struct port *port;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL || info == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
if (!IS_VALID_PORT (this, direction, port_id))
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
*info = &port->info;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_enum_params (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2017-05-22 11:06:18 +00:00
|
|
|
uint32_t port_id,
|
|
|
|
uint32_t index,
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_param **param)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_set_param (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2016-07-13 16:29:55 +00:00
|
|
|
uint32_t port_id,
|
2017-05-25 11:28:15 +00:00
|
|
|
const struct spa_param *param)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_use_buffers (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
|
|
|
uint32_t port_id,
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
uint32_t n_buffers)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
if (!IS_VALID_PORT (node, direction, port_id))
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
2016-08-02 14:34:44 +00:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-07-13 16:29:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_alloc_buffers (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
|
|
|
uint32_t port_id,
|
|
|
|
struct spa_param **params,
|
|
|
|
uint32_t n_params,
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
uint32_t *n_buffers)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_set_io (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
2017-04-03 12:56:04 +00:00
|
|
|
uint32_t port_id,
|
2017-05-25 11:28:15 +00:00
|
|
|
struct spa_port_io *io)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
|
|
|
struct port *port;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2016-11-07 17:23:09 +00:00
|
|
|
if (node == NULL)
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2017-04-03 12:56:04 +00:00
|
|
|
if (!IS_VALID_PORT (this, direction, port_id))
|
2016-11-07 17:23:09 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-04-03 12:56:04 +00:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
port->io = io;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_reuse_buffer (struct spa_node *node,
|
2016-10-03 17:43:42 +00:00
|
|
|
uint32_t port_id,
|
|
|
|
uint32_t buffer_id)
|
|
|
|
{
|
2016-10-12 15:27:29 +00:00
|
|
|
if (node == NULL)
|
2016-10-03 17:43:42 +00:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2016-10-04 13:56:33 +00:00
|
|
|
if (port_id != 0)
|
2016-10-03 17:43:42 +00:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_port_send_command (struct spa_node *node,
|
|
|
|
enum spa_direction direction,
|
|
|
|
uint32_t port_id,
|
|
|
|
struct spa_command *command)
|
2016-07-30 18:35:34 +00:00
|
|
|
{
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_process_input (struct spa_node *node)
|
2016-11-07 17:23:09 +00:00
|
|
|
{
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_node_process_output (struct spa_node *node)
|
2016-11-07 17:23:09 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
|
|
|
struct port *port;
|
|
|
|
struct spa_port_io *output;
|
2016-11-07 17:23:09 +00:00
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = SPA_CONTAINER_OF (node, struct impl, node);
|
2016-11-07 17:23:09 +00:00
|
|
|
|
|
|
|
if ((output = this->out_ports[0].io) == NULL)
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
|
|
|
port = &this->out_ports[0];
|
|
|
|
|
2017-02-28 09:48:53 +00:00
|
|
|
if (!port->have_format) {
|
2016-11-07 17:23:09 +00:00
|
|
|
output->status = SPA_RESULT_NO_FORMAT;
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
}
|
|
|
|
output->status = SPA_RESULT_OK;
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static const struct spa_node ffmpeg_enc_node = {
|
|
|
|
sizeof (struct spa_node),
|
2016-09-15 15:51:34 +00:00
|
|
|
NULL,
|
2016-07-13 16:29:55 +00:00
|
|
|
spa_ffmpeg_enc_node_get_props,
|
|
|
|
spa_ffmpeg_enc_node_set_props,
|
|
|
|
spa_ffmpeg_enc_node_send_command,
|
2017-05-11 08:29:20 +00:00
|
|
|
spa_ffmpeg_enc_node_set_callbacks,
|
2016-07-13 16:29:55 +00:00
|
|
|
spa_ffmpeg_enc_node_get_n_ports,
|
|
|
|
spa_ffmpeg_enc_node_get_port_ids,
|
|
|
|
spa_ffmpeg_enc_node_add_port,
|
|
|
|
spa_ffmpeg_enc_node_remove_port,
|
|
|
|
spa_ffmpeg_enc_node_port_enum_formats,
|
|
|
|
spa_ffmpeg_enc_node_port_set_format,
|
|
|
|
spa_ffmpeg_enc_node_port_get_format,
|
|
|
|
spa_ffmpeg_enc_node_port_get_info,
|
2017-05-22 11:06:18 +00:00
|
|
|
spa_ffmpeg_enc_node_port_enum_params,
|
|
|
|
spa_ffmpeg_enc_node_port_set_param,
|
2016-07-13 16:29:55 +00:00
|
|
|
spa_ffmpeg_enc_node_port_use_buffers,
|
|
|
|
spa_ffmpeg_enc_node_port_alloc_buffers,
|
2017-04-03 12:56:04 +00:00
|
|
|
spa_ffmpeg_enc_node_port_set_io,
|
2016-10-03 17:43:42 +00:00
|
|
|
spa_ffmpeg_enc_node_port_reuse_buffer,
|
2016-10-21 12:57:01 +00:00
|
|
|
spa_ffmpeg_enc_node_port_send_command,
|
2016-11-07 17:23:09 +00:00
|
|
|
spa_ffmpeg_enc_node_process_input,
|
|
|
|
spa_ffmpeg_enc_node_process_output,
|
2016-07-13 16:29:55 +00:00
|
|
|
};
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
static int
|
|
|
|
spa_ffmpeg_enc_get_interface (struct spa_handle *handle,
|
2016-07-30 18:35:34 +00:00
|
|
|
uint32_t interface_id,
|
|
|
|
void **interface)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2016-07-13 16:29:55 +00:00
|
|
|
if (handle == NULL || interface == NULL)
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = (struct impl *) handle;
|
2016-07-30 18:35:34 +00:00
|
|
|
|
2017-03-24 10:40:58 +00:00
|
|
|
if (interface_id == this->type.node)
|
2016-10-07 11:14:32 +00:00
|
|
|
*interface = &this->node;
|
|
|
|
else
|
|
|
|
return SPA_RESULT_UNKNOWN_INTERFACE;
|
|
|
|
|
2016-07-13 16:29:55 +00:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
int
|
|
|
|
spa_ffmpeg_enc_init (struct spa_handle *handle,
|
|
|
|
const struct spa_dict *info,
|
|
|
|
const struct spa_support *support,
|
|
|
|
uint32_t n_support)
|
2016-07-13 16:29:55 +00:00
|
|
|
{
|
2017-05-25 11:28:15 +00:00
|
|
|
struct impl *this;
|
2017-03-07 10:56:43 +00:00
|
|
|
uint32_t i;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
handle->get_interface = spa_ffmpeg_enc_get_interface;
|
|
|
|
|
2017-05-25 11:28:15 +00:00
|
|
|
this = (struct impl *) handle;
|
2016-10-07 11:14:32 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_support; i++) {
|
2017-03-24 10:40:58 +00:00
|
|
|
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
|
2016-10-07 11:14:32 +00:00
|
|
|
this->map = support[i].data;
|
2017-03-24 10:40:58 +00:00
|
|
|
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
2016-10-07 11:14:32 +00:00
|
|
|
this->log = support[i].data;
|
|
|
|
}
|
|
|
|
if (this->map == NULL) {
|
2017-03-24 10:40:58 +00:00
|
|
|
spa_log_error (this->log, "a type-map is needed");
|
2016-10-07 11:14:32 +00:00
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-07-30 18:35:34 +00:00
|
|
|
this->node = ffmpeg_enc_node;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
2017-05-11 08:29:20 +00:00
|
|
|
this->in_ports[0].info.flags = 0;
|
|
|
|
this->out_ports[0].info.flags = 0;
|
2016-07-13 16:29:55 +00:00
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
}
|