mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-17 08:56:49 -05:00
Add logger
Add logger interface Make it possible to pass extra interfaces to the element at init time, such as a logger.
This commit is contained in:
parent
e90c53e48d
commit
49dae17dfb
26 changed files with 251 additions and 47 deletions
|
|
@ -88,7 +88,7 @@ make_handle (SpaHandle **handle, const char *lib, const char *name, const SpaDic
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
*handle = g_malloc0 (factory->size);
|
*handle = g_malloc0 (factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, *handle, info)) < 0) {
|
if ((res = spa_handle_factory_init (factory, *handle, info, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +110,7 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
||||||
g_debug ("alsa-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
g_debug ("alsa-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||||
|
|
||||||
handle = calloc (1, item->factory->size);
|
handle = calloc (1, item->factory->size);
|
||||||
if ((res = spa_handle_factory_init (item->factory, handle, item->info)) < 0) {
|
if ((res = spa_handle_factory_init (item->factory, handle, item->info, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, handle, NULL)) < 0) {
|
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ make_handle (SpaHandle **handle, const char *lib, const char *name, const SpaDic
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
*handle = g_malloc0 (factory->size);
|
*handle = g_malloc0 (factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, *handle, info)) < 0) {
|
if ((res = spa_handle_factory_init (factory, *handle, info, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +110,7 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
||||||
g_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
g_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||||
|
|
||||||
handle = calloc (1, item->factory->size);
|
handle = calloc (1, item->factory->size);
|
||||||
if ((res = spa_handle_factory_init (item->factory, handle, item->info)) < 0) {
|
if ((res = spa_handle_factory_init (item->factory, handle, item->info, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = factory->init (factory, handle, NULL)) < 0) {
|
if ((res = factory->init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = factory->init (factory, handle, NULL)) < 0) {
|
if ((res = factory->init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
g_error ("can't make factory instance: %d", res);
|
g_error ("can't make factory instance: %d", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ loop (void *user_data)
|
||||||
for (i = 0; i < priv->n_poll; i++) {
|
for (i = 0; i < priv->n_poll; i++) {
|
||||||
SpaPollItem *p = &priv->poll[i];
|
SpaPollItem *p = &priv->poll[i];
|
||||||
|
|
||||||
if (p->enabled && p->after_cb) {
|
if (p->enabled && p->after_cb && (p->n_fds == 0 || priv->fds[priv->idx[i]].revents != 0)) {
|
||||||
ndata.fds = &priv->fds[priv->idx[i]];
|
ndata.fds = &priv->fds[priv->idx[i]];
|
||||||
ndata.n_fds = p->n_fds;
|
ndata.n_fds = p->n_fds;
|
||||||
ndata.user_data = p->user_data;
|
ndata.user_data = p->user_data;
|
||||||
|
|
|
||||||
150
spa/include/spa/log.h
Normal file
150
spa/include/spa/log.h
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
/* Simple Plugin API
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SPA_LOG_H__
|
||||||
|
#define __SPA_LOG_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct _SpaLog SpaLog;
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include <spa/defs.h>
|
||||||
|
#include <spa/plugin.h>
|
||||||
|
|
||||||
|
#define SPA_INTERFACE_ID_LOG 3
|
||||||
|
#define SPA_INTERFACE_ID_LOG_NAME "Log interface"
|
||||||
|
#define SPA_INTERFACE_ID_LOG_DESCRIPTION "Log interface"
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SPA_LOG_LEVEL_NONE = 0,
|
||||||
|
SPA_LOG_LEVEL_ERROR,
|
||||||
|
SPA_LOG_LEVEL_WARN,
|
||||||
|
SPA_LOG_LEVEL_INFO,
|
||||||
|
SPA_LOG_LEVEL_DEBUG,
|
||||||
|
SPA_LOG_LEVEL_TRACE,
|
||||||
|
} SpaLogLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpaLog:
|
||||||
|
*
|
||||||
|
* The Log interface
|
||||||
|
*/
|
||||||
|
struct _SpaLog {
|
||||||
|
/* pointer to the handle owning this interface */
|
||||||
|
SpaHandle *handle;
|
||||||
|
/* the total size of this log. This can be used to expand this
|
||||||
|
* structure in the future */
|
||||||
|
size_t size;
|
||||||
|
/**
|
||||||
|
* SpaLog::info
|
||||||
|
*
|
||||||
|
* Extra information about the log
|
||||||
|
*/
|
||||||
|
const SpaDict *info;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpaLog::level
|
||||||
|
*
|
||||||
|
* Logging level, everything above this level is not logged
|
||||||
|
*/
|
||||||
|
SpaLogLevel level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpaLog::log
|
||||||
|
* @log: a #SpaLog
|
||||||
|
* @level: a #SpaLogLevel
|
||||||
|
* @file: the file name
|
||||||
|
* @line: the line number
|
||||||
|
* @func: the function name
|
||||||
|
* @fmt: printf style format
|
||||||
|
* @...: format arguments
|
||||||
|
*
|
||||||
|
* Log a message with the given log level.
|
||||||
|
*/
|
||||||
|
void (*log) (SpaLog *log,
|
||||||
|
SpaLogLevel level,
|
||||||
|
const char *file,
|
||||||
|
int line,
|
||||||
|
const char *func,
|
||||||
|
const char *fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpaLog::logv
|
||||||
|
* @log: a #SpaLog
|
||||||
|
* @level: a #SpaLogLevel
|
||||||
|
* @file: the file name
|
||||||
|
* @line: the line number
|
||||||
|
* @func: the function name
|
||||||
|
* @fmt: printf style format
|
||||||
|
* @args: format arguments
|
||||||
|
*
|
||||||
|
* Log a message with the given log level.
|
||||||
|
*/
|
||||||
|
void (*logv) (SpaLog *log,
|
||||||
|
SpaLogLevel level,
|
||||||
|
const char *file,
|
||||||
|
int line,
|
||||||
|
const char *func,
|
||||||
|
const char *fmt,
|
||||||
|
va_list args);
|
||||||
|
};
|
||||||
|
|
||||||
|
#if __STDC_VERSION__ >= 199901L
|
||||||
|
|
||||||
|
#define spa_log_log(l,lev,...) \
|
||||||
|
if ((l) && (l)->level > lev) \
|
||||||
|
(l)->log((l),lev,__VA_ARGS__)
|
||||||
|
|
||||||
|
#define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||||
|
#define spa_log_warn(l,...) spa_log_log(l,SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||||
|
#define spa_log_info(l,...) spa_log_log(l,SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||||
|
#define spa_log_debug(l,...) spa_log_log(l,SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||||
|
#define spa_log_trace(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define SPA_LOG_FUNC(name,lev) \
|
||||||
|
static inline void spa_log_##name (SpaLog *l, const char *format, ...) \
|
||||||
|
{ \
|
||||||
|
if ((l) && (l)->level > lev) { \
|
||||||
|
va_list varargs; \
|
||||||
|
va_start (varargs, format); \
|
||||||
|
(l)->logv((l),lev,__FILE__,__LINE__,__func__,format,varargs); \
|
||||||
|
va_end (varargs); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
SPA_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR)
|
||||||
|
SPA_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN)
|
||||||
|
SPA_LOG_FUNC(info, SPA_LOG_LEVEL_INFO)
|
||||||
|
SPA_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG)
|
||||||
|
SPA_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __SPA_LOG_H__ */
|
||||||
|
|
@ -6,6 +6,7 @@ spa_headers = [
|
||||||
'defs.h',
|
'defs.h',
|
||||||
'dict.h',
|
'dict.h',
|
||||||
'format.h',
|
'format.h',
|
||||||
|
'log.h',
|
||||||
'monitor.h',
|
'monitor.h',
|
||||||
'node-command.h',
|
'node-command.h',
|
||||||
'node-event.h',
|
'node-event.h',
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,19 @@ typedef struct {
|
||||||
const char *description;
|
const char *description;
|
||||||
} SpaInterfaceInfo;
|
} SpaInterfaceInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpaInterface:
|
||||||
|
* @interface_id: the id of the interface
|
||||||
|
* @interface: an interface instance
|
||||||
|
*
|
||||||
|
* An interface instance that is usually passed to the init() function of
|
||||||
|
* a factory to provide extra API such as logging.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t interface_id;
|
||||||
|
void *interface;
|
||||||
|
} SpaInterface;
|
||||||
|
|
||||||
struct _SpaHandleFactory {
|
struct _SpaHandleFactory {
|
||||||
/**
|
/**
|
||||||
* SpaHandleFactory::name
|
* SpaHandleFactory::name
|
||||||
|
|
@ -104,17 +117,24 @@ struct _SpaHandleFactory {
|
||||||
* @handle: a pointer to memory
|
* @handle: a pointer to memory
|
||||||
* @info: extra handle specific information, usually obtained
|
* @info: extra handle specific information, usually obtained
|
||||||
* from a #SpaMonitor. This can be used to configure the handle.
|
* from a #SpaMonitor. This can be used to configure the handle.
|
||||||
|
* @platform: platform interfaces
|
||||||
|
* @n_platform: number of elements in @platform
|
||||||
*
|
*
|
||||||
* Initialize an instance of this factory. The caller should allocate
|
* Initialize an instance of this factory. The caller should allocate
|
||||||
* memory at least SpaHandleFactory::size bytes and pass this as @handle.
|
* memory at least SpaHandleFactory::size bytes and pass this as @handle.
|
||||||
*
|
*
|
||||||
|
* @platform can optionally contain extra interfaces that the plugin can
|
||||||
|
* use such as a logger.
|
||||||
|
*
|
||||||
* Returns: #SPA_RESULT_OK on success
|
* Returns: #SPA_RESULT_OK on success
|
||||||
* #SPA_RESULT_NOT_IMPLEMENTED when an instance can't be made
|
* #SPA_RESULT_NOT_IMPLEMENTED when an instance can't be made
|
||||||
* #SPA_RESULT_INVALID_ARGUMENTS when factory or handle are %NULL
|
* #SPA_RESULT_INVALID_ARGUMENTS when factory or handle are %NULL
|
||||||
*/
|
*/
|
||||||
SpaResult (*init) (const SpaHandleFactory *factory,
|
SpaResult (*init) (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info);
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SpaHandle::enum_interface_info:
|
* SpaHandle::enum_interface_info:
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,9 @@ alsa_monitor_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
alsa_monitor_init (const SpaHandleFactory *factory,
|
alsa_monitor_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaALSAMonitor *this;
|
SpaALSAMonitor *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -598,7 +598,9 @@ alsa_sink_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
alsa_sink_init (const SpaHandleFactory *factory,
|
alsa_sink_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaALSASink *this;
|
SpaALSASink *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -751,7 +751,9 @@ alsa_source_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
alsa_source_init (const SpaHandleFactory *factory,
|
alsa_source_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaALSASource *this;
|
SpaALSASource *this;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
|
||||||
|
|
@ -779,7 +779,9 @@ spa_audiomixer_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
spa_audiomixer_init (const SpaHandleFactory *factory,
|
spa_audiomixer_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaAudioMixer *this;
|
SpaAudioMixer *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -988,7 +988,9 @@ audiotestsrc_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
audiotestsrc_init (const SpaHandleFactory *factory,
|
audiotestsrc_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaAudioTestSrc *this;
|
SpaAudioTestSrc *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,9 @@ SpaResult spa_ffmpeg_enc_init (SpaHandle *handle);
|
||||||
static SpaResult
|
static SpaResult
|
||||||
ffmpeg_dec_init (const SpaHandleFactory *factory,
|
ffmpeg_dec_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
if (factory == NULL || handle == NULL)
|
if (factory == NULL || handle == NULL)
|
||||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||||
|
|
@ -42,7 +44,9 @@ ffmpeg_dec_init (const SpaHandleFactory *factory,
|
||||||
static SpaResult
|
static SpaResult
|
||||||
ffmpeg_enc_init (const SpaHandleFactory *factory,
|
ffmpeg_enc_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
if (factory == NULL || handle == NULL)
|
if (factory == NULL || handle == NULL)
|
||||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||||
|
|
|
||||||
|
|
@ -1347,7 +1347,9 @@ proxy_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
proxy_init (const SpaHandleFactory *factory,
|
proxy_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaProxy *this;
|
SpaProxy *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,9 @@ v4l2_monitor_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
v4l2_monitor_init (const SpaHandleFactory *factory,
|
v4l2_monitor_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaV4l2Monitor *this;
|
SpaV4l2Monitor *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <spa/video/format.h>
|
#include <spa/video/format.h>
|
||||||
#include <spa/debug.h>
|
#include <spa/debug.h>
|
||||||
#include <spa/queue.h>
|
#include <spa/queue.h>
|
||||||
|
#include <spa/log.h>
|
||||||
|
|
||||||
typedef struct _SpaV4l2Source SpaV4l2Source;
|
typedef struct _SpaV4l2Source SpaV4l2Source;
|
||||||
|
|
||||||
|
|
@ -111,6 +112,8 @@ typedef struct {
|
||||||
SpaAllocParamMetaEnable param_meta;
|
SpaAllocParamMetaEnable param_meta;
|
||||||
SpaPortStatus status;
|
SpaPortStatus status;
|
||||||
|
|
||||||
|
SpaLog *log;
|
||||||
|
|
||||||
int64_t last_ticks;
|
int64_t last_ticks;
|
||||||
int64_t last_monotonic;
|
int64_t last_monotonic;
|
||||||
} SpaV4l2State;
|
} SpaV4l2State;
|
||||||
|
|
@ -827,7 +830,9 @@ v4l2_source_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
v4l2_source_init (const SpaHandleFactory *factory,
|
v4l2_source_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaV4l2Source *this;
|
SpaV4l2Source *this;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
@ -849,6 +854,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
||||||
|
|
||||||
SPA_QUEUE_INIT (&this->state[0].ready);
|
SPA_QUEUE_INIT (&this->state[0].ready);
|
||||||
|
|
||||||
|
this->state[0].log = NULL;
|
||||||
this->state[0].info.flags = SPA_PORT_INFO_FLAG_LIVE;
|
this->state[0].info.flags = SPA_PORT_INFO_FLAG_LIVE;
|
||||||
this->state[0].status.flags = SPA_PORT_STATUS_FLAG_NONE;
|
this->state[0].status.flags = SPA_PORT_STATUS_FLAG_NONE;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,27 +32,27 @@ spa_v4l2_open (SpaV4l2Source *this)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (props->props.unset_mask & 1) {
|
if (props->props.unset_mask & 1) {
|
||||||
fprintf(stderr, "v4l2: Device property not set\n");
|
spa_log_error (state->log, "v4l2: Device property not set\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "v4l2: Playback device is '%s'\n", props->device);
|
spa_log_info (state->log, "v4l2: Playback device is '%s'\n", props->device);
|
||||||
|
|
||||||
if (stat (props->device, &st) < 0) {
|
if (stat (props->device, &st) < 0) {
|
||||||
fprintf(stderr, "v4l2: Cannot identify '%s': %d, %s\n",
|
spa_log_error (state->log, "v4l2: Cannot identify '%s': %d, %s\n",
|
||||||
props->device, errno, strerror (errno));
|
props->device, errno, strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISCHR (st.st_mode)) {
|
if (!S_ISCHR (st.st_mode)) {
|
||||||
fprintf(stderr, "v4l2: %s is no device\n", props->device);
|
spa_log_error (state->log, "v4l2: %s is no device\n", props->device);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->fd = open (props->device, O_RDWR | O_NONBLOCK, 0);
|
state->fd = open (props->device, O_RDWR | O_NONBLOCK, 0);
|
||||||
|
|
||||||
if (state->fd == -1) {
|
if (state->fd == -1) {
|
||||||
fprintf (stderr, "v4l2: Cannot open '%s': %d, %s\n",
|
spa_log_error (state->log, "v4l2: Cannot open '%s': %d, %s\n",
|
||||||
props->device, errno, strerror (errno));
|
props->device, errno, strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ spa_v4l2_open (SpaV4l2Source *this)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((state->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
|
if ((state->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
|
||||||
fprintf (stderr, "v4l2: %s is no video capture device\n", props->device);
|
spa_log_error (state->log, "v4l2: %s is no video capture device\n", props->device);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
state->opened = true;
|
state->opened = true;
|
||||||
|
|
@ -103,7 +103,7 @@ spa_v4l2_clear_buffers (SpaV4l2Source *this)
|
||||||
|
|
||||||
b = &state->buffers[i];
|
b = &state->buffers[i];
|
||||||
if (b->outstanding) {
|
if (b->outstanding) {
|
||||||
fprintf (stderr, "v4l2: queueing outstanding buffer %p\n", b);
|
spa_log_info (state->log, "v4l2: queueing outstanding buffer %p\n", b);
|
||||||
spa_v4l2_buffer_recycle (this, i);
|
spa_v4l2_buffer_recycle (this, i);
|
||||||
}
|
}
|
||||||
if (b->allocated) {
|
if (b->allocated) {
|
||||||
|
|
@ -139,7 +139,7 @@ spa_v4l2_close (SpaV4l2Source *this)
|
||||||
if (state->n_buffers > 0)
|
if (state->n_buffers > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fprintf (stderr, "v4l2: close\n");
|
spa_log_info (state->log, "v4l2: close\n");
|
||||||
if (close(state->fd))
|
if (close(state->fd))
|
||||||
perror ("close");
|
perror ("close");
|
||||||
|
|
||||||
|
|
@ -749,7 +749,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only)
|
||||||
f->format,
|
f->format,
|
||||||
0);
|
0);
|
||||||
if (info == NULL) {
|
if (info == NULL) {
|
||||||
fprintf (stderr, "v4l2: unknown media type %d %d %d\n", f->fmt.media_type,
|
spa_log_error (state->log, "v4l2: unknown media type %d %d %d\n", f->fmt.media_type,
|
||||||
f->fmt.media_subtype, f->format);
|
f->fmt.media_subtype, f->format);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -761,7 +761,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only)
|
||||||
streamparm.parm.capture.timeperframe.numerator = f->framerate.denom;
|
streamparm.parm.capture.timeperframe.numerator = f->framerate.denom;
|
||||||
streamparm.parm.capture.timeperframe.denominator = f->framerate.num;
|
streamparm.parm.capture.timeperframe.denominator = f->framerate.num;
|
||||||
|
|
||||||
fprintf (stderr, "v4l2: set %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat,
|
spa_log_info (state->log, "v4l2: set %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat,
|
||||||
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
||||||
streamparm.parm.capture.timeperframe.numerator,
|
streamparm.parm.capture.timeperframe.numerator,
|
||||||
streamparm.parm.capture.timeperframe.denominator);
|
streamparm.parm.capture.timeperframe.denominator);
|
||||||
|
|
@ -781,7 +781,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only)
|
||||||
if (xioctl (state->fd, VIDIOC_S_PARM, &streamparm) < 0)
|
if (xioctl (state->fd, VIDIOC_S_PARM, &streamparm) < 0)
|
||||||
perror ("VIDIOC_S_PARM");
|
perror ("VIDIOC_S_PARM");
|
||||||
|
|
||||||
fprintf (stderr, "v4l2: got %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat,
|
spa_log_info (state->log, "v4l2: got %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat,
|
||||||
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
||||||
streamparm.parm.capture.timeperframe.numerator,
|
streamparm.parm.capture.timeperframe.numerator,
|
||||||
streamparm.parm.capture.timeperframe.denominator);
|
streamparm.parm.capture.timeperframe.denominator);
|
||||||
|
|
@ -882,6 +882,9 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
|
||||||
if (data->fds[0].revents & POLLERR)
|
if (data->fds[0].revents & POLLERR)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!(data->fds[0].revents & POLLIN))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (mmap_read (this) < 0)
|
if (mmap_read (this) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
@ -912,7 +915,7 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
|
||||||
state->memtype = V4L2_MEMORY_DMABUF;
|
state->memtype = V4L2_MEMORY_DMABUF;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf (stderr, "v4l2: can't use buffers\n");
|
spa_log_error (state->log, "v4l2: can't use buffers\n");
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -926,9 +929,9 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
|
||||||
perror ("VIDIOC_REQBUFS");
|
perror ("VIDIOC_REQBUFS");
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
fprintf (stderr, "v4l2: got %d buffers\n", reqbuf.count);
|
spa_log_info (state->log, "v4l2: got %d buffers\n", reqbuf.count);
|
||||||
if (reqbuf.count < 2) {
|
if (reqbuf.count < 2) {
|
||||||
fprintf (stderr, "v4l2: can't allocate enough buffers\n");
|
spa_log_error (state->log, "v4l2: can't allocate enough buffers\n");
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -941,10 +944,10 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
|
||||||
b->allocated = false;
|
b->allocated = false;
|
||||||
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER);
|
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER);
|
||||||
|
|
||||||
fprintf (stderr, "v4l2: import buffer %p\n", buffers[i]);
|
spa_log_info (state->log, "v4l2: import buffer %p\n", buffers[i]);
|
||||||
|
|
||||||
if (buffers[i]->n_datas < 1) {
|
if (buffers[i]->n_datas < 1) {
|
||||||
fprintf (stderr, "v4l2: invalid memory on buffer %p\n", buffers[i]);
|
spa_log_error (state->log, "v4l2: invalid memory on buffer %p\n", buffers[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
d = buffers[i]->datas;
|
d = buffers[i]->datas;
|
||||||
|
|
@ -957,7 +960,7 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
|
||||||
case SPA_DATA_TYPE_MEMPTR:
|
case SPA_DATA_TYPE_MEMPTR:
|
||||||
case SPA_DATA_TYPE_MEMFD:
|
case SPA_DATA_TYPE_MEMFD:
|
||||||
if (d[0].data == NULL) {
|
if (d[0].data == NULL) {
|
||||||
fprintf (stderr, "v4l2: need mmaped memory\n");
|
spa_log_error (state->log, "v4l2: need mmaped memory\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (d[0].data, d[0].offset, void *);
|
b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (d[0].data, d[0].offset, void *);
|
||||||
|
|
@ -999,22 +1002,22 @@ mmap_init (SpaV4l2Source *this,
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "v4l2: got %d buffers\n", reqbuf.count);
|
spa_log_info (state->log, "v4l2: got %d buffers\n", reqbuf.count);
|
||||||
*n_buffers = reqbuf.count;
|
*n_buffers = reqbuf.count;
|
||||||
|
|
||||||
if (reqbuf.count < 2) {
|
if (reqbuf.count < 2) {
|
||||||
fprintf (stderr, "v4l2: can't allocate enough buffers\n");
|
spa_log_error (state->log, "v4l2: can't allocate enough buffers\n");
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
if (state->export_buf)
|
if (state->export_buf)
|
||||||
fprintf (stderr, "v4l2: using EXPBUF\n");
|
spa_log_info (state->log, "v4l2: using EXPBUF\n");
|
||||||
|
|
||||||
for (i = 0; i < reqbuf.count; i++) {
|
for (i = 0; i < reqbuf.count; i++) {
|
||||||
V4l2Buffer *b;
|
V4l2Buffer *b;
|
||||||
SpaData *d;
|
SpaData *d;
|
||||||
|
|
||||||
if (buffers[i]->n_datas < 1) {
|
if (buffers[i]->n_datas < 1) {
|
||||||
fprintf (stderr, "v4l2: invalid buffer data\n");
|
spa_log_error (state->log, "v4l2: invalid buffer data\n");
|
||||||
return SPA_RESULT_ERROR;
|
return SPA_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -936,7 +936,9 @@ videotestsrc_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
videotestsrc_init (const SpaHandleFactory *factory,
|
videotestsrc_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaVideoTestSrc *this;
|
SpaVideoTestSrc *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -676,7 +676,9 @@ volume_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
volume_init (const SpaHandleFactory *factory,
|
volume_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaVolume *this;
|
SpaVolume *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -557,7 +557,9 @@ xv_sink_clear (SpaHandle *handle)
|
||||||
static SpaResult
|
static SpaResult
|
||||||
xv_sink_init (const SpaHandleFactory *factory,
|
xv_sink_init (const SpaHandleFactory *factory,
|
||||||
SpaHandle *handle,
|
SpaHandle *handle,
|
||||||
const SpaDict *info)
|
const SpaDict *info,
|
||||||
|
const SpaInterface **platform,
|
||||||
|
unsigned int n_platform)
|
||||||
{
|
{
|
||||||
SpaXvSink *this;
|
SpaXvSink *this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, handle, NULL)) < 0) {
|
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
printf ("can't make factory instance: %d\n", res);
|
printf ("can't make factory instance: %d\n", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, handle, NULL)) < 0) {
|
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
printf ("can't make factory instance: %d\n", res);
|
printf ("can't make factory instance: %d\n", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ inspect_factory (const SpaHandleFactory *factory)
|
||||||
printf (" none\n");
|
printf (" none\n");
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, handle, NULL)) < 0) {
|
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
printf ("can't make factory instance: %d\n", res);
|
printf ("can't make factory instance: %d\n", res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ main (int argc, char *argv[])
|
||||||
void *interface;
|
void *interface;
|
||||||
|
|
||||||
handle = calloc (1, factory->size);
|
handle = calloc (1, factory->size);
|
||||||
if ((res = spa_handle_factory_init (factory, handle, NULL)) < 0) {
|
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||||
printf ("can't make factory instance: %d\n", res);
|
printf ("can't make factory instance: %d\n", res);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue