2016-07-13 18:29:55 +02:00
|
|
|
/* Spa V4l2 support
|
|
|
|
|
* 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 <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include <spa/plugin.h>
|
|
|
|
|
#include <spa/node.h>
|
|
|
|
|
|
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
|
2017-03-07 11:56:43 +01:00
|
|
|
SpaResult spa_ffmpeg_dec_init (SpaHandle *handle, const SpaDict *info, const SpaSupport *support, uint32_t n_support);
|
|
|
|
|
SpaResult spa_ffmpeg_enc_init (SpaHandle *handle, const SpaDict *info, const SpaSupport *support, uint32_t n_support);
|
2016-07-13 18:29:55 +02:00
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
ffmpeg_dec_init (const SpaHandleFactory *factory,
|
2016-09-15 11:49:34 +02:00
|
|
|
SpaHandle *handle,
|
2016-10-05 17:43:11 +02:00
|
|
|
const SpaDict *info,
|
2016-10-07 13:14:32 +02:00
|
|
|
const SpaSupport *support,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_support)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
|
|
|
|
if (factory == NULL || handle == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-07 13:14:32 +02:00
|
|
|
return spa_ffmpeg_dec_init (handle, info, support, n_support);
|
2016-07-13 18:29:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
ffmpeg_enc_init (const SpaHandleFactory *factory,
|
2016-09-15 11:49:34 +02:00
|
|
|
SpaHandle *handle,
|
2016-10-05 17:43:11 +02:00
|
|
|
const SpaDict *info,
|
2016-10-07 13:14:32 +02:00
|
|
|
const SpaSupport *support,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_support)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
|
|
|
|
if (factory == NULL || handle == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-07 13:14:32 +02:00
|
|
|
return spa_ffmpeg_enc_init (handle, info, support, n_support);
|
2016-07-13 18:29:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const SpaInterfaceInfo ffmpeg_interfaces[] =
|
|
|
|
|
{
|
2016-10-07 13:14:32 +02:00
|
|
|
{ SPA_NODE_URI,
|
2016-07-13 18:29:55 +02:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
ffmpeg_enum_interface_info (const SpaHandleFactory *factory,
|
2016-07-15 18:22:29 +02:00
|
|
|
const SpaInterfaceInfo **info,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
2017-02-01 08:58:21 +01:00
|
|
|
if (factory == NULL || info == NULL)
|
2016-07-15 18:22:29 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-13 18:29:55 +02:00
|
|
|
if (index >= 1)
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
|
|
|
|
|
*info = &ffmpeg_interfaces[index];
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SpaResult
|
2016-07-15 18:22:29 +02:00
|
|
|
spa_enum_handle_factory (const SpaHandleFactory **factory,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
|
|
|
|
static const AVCodec *c = NULL;
|
|
|
|
|
static int ci = 0;
|
|
|
|
|
static SpaHandleFactory f;
|
|
|
|
|
static char name[128];
|
|
|
|
|
|
|
|
|
|
av_register_all();
|
|
|
|
|
|
2017-02-01 08:58:21 +01:00
|
|
|
if (index == 0) {
|
2016-07-13 18:29:55 +02:00
|
|
|
c = av_codec_next (NULL);
|
|
|
|
|
ci = 0;
|
|
|
|
|
}
|
|
|
|
|
while (index > ci && c) {
|
|
|
|
|
c = av_codec_next (c);
|
|
|
|
|
ci++;
|
|
|
|
|
}
|
|
|
|
|
if (c == NULL)
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
|
|
|
|
|
if (av_codec_is_encoder (c)) {
|
|
|
|
|
snprintf (name, 128, "ffenc_%s", c->name);
|
|
|
|
|
f.init = ffmpeg_enc_init;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
snprintf (name, 128, "ffdec_%s", c->name);
|
|
|
|
|
f.init = ffmpeg_dec_init;
|
|
|
|
|
}
|
|
|
|
|
f.name = name;
|
|
|
|
|
f.info = NULL;
|
|
|
|
|
f.enum_interface_info = ffmpeg_enum_interface_info;
|
|
|
|
|
|
|
|
|
|
*factory = &f;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|