Origin commit data
------------------
Branch: master
Commit: b018b10a66
Author: martii <m4rtii@gmx.de>
Date: 2013-06-01 (Sat, 01 Jun 2013)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
martii
2013-06-01 17:21:07 +02:00
7 changed files with 129 additions and 135 deletions

View File

@@ -9,14 +9,7 @@ libstb_hal_la_LIBADD = \
common/libcommon.la common/libcommon.la
libstb_hal_test_SOURCES = libtest.cpp libstb_hal_test_SOURCES = libtest.cpp
libstb_hal_test_LDADD = \ libstb_hal_test_LDADD = libstb-hal.la
libstb-hal.la \
-lpthread
if BOXTYPE_TRIPLE
libstb_hal_test_LDADD += \
@DIRECTFB_LIBS@
endif
# there has to be a better way to do this... # there has to be a better way to do this...
if BOXTYPE_TRIPLE if BOXTYPE_TRIPLE
@@ -33,15 +26,6 @@ if BOXTYPE_GENERIC
SUBDIRS += generic-pc SUBDIRS += generic-pc
libstb_hal_la_LIBADD += \ libstb_hal_la_LIBADD += \
generic-pc/libgeneric.la generic-pc/libgeneric.la
libstb_hal_test_LDADD += \
-lglut -lGL -lGLU -lGLEW -lao \
-lOpenThreads \
@AVFORMAT_LIBS@ \
@AVUTIL_LIBS@ \
@AVCODEC_LIBS@ \
@SWRESAMPLE_LIBS@ \
@SWSCALE_LIBS@
endif endif
if BOXTYPE_SPARK if BOXTYPE_SPARK
libstb_hal_test_LDADD += -lasound libstb_hal_test_LDADD += -lasound

View File

@@ -6,6 +6,15 @@ noinst_LTLIBRARIES = libgeneric.la
AM_CPPFLAGS = -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS AM_CPPFLAGS = -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS
AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing
AM_LDFLAGS = \
-lglut -lGL -lGLU -lGLEW -lao \
-lOpenThreads \
@AVFORMAT_LIBS@ \
@AVUTIL_LIBS@ \
@AVCODEC_LIBS@ \
@SWRESAMPLE_LIBS@ \
@SWSCALE_LIBS@
libgeneric_la_SOURCES = \ libgeneric_la_SOURCES = \
hardware_caps.c \ hardware_caps.c \
dmx.cpp \ dmx.cpp \

View File

@@ -16,7 +16,7 @@
* *
* cAudio implementation with decoder. * cAudio implementation with decoder.
* uses libao <http://www.xiph.org/ao/> for output * uses libao <http://www.xiph.org/ao/> for output
* ffmpeg <http://ffmpeg.org> for demuxing / decoding * ffmpeg <http://ffmpeg.org> for demuxing / decoding / format conversion
*/ */
#include <cstdio> #include <cstdio>
@@ -33,28 +33,15 @@
extern "C" { extern "C" {
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavutil/opt.h>
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
#include <ao/ao.h> #include <ao/ao.h>
#ifdef MARTII
#define USE_LIBSWRESAMPLE
# ifdef USE_LIBSWRESAMPLE
# include <libswresample/swresample.h>
# else
# include <libavresample/avresample.h>
# endif
# include <libavutil/opt.h>
#endif
} }
#ifdef MARTII
/* ffmpeg buf 8k */
#define INBUF_SIZE 0x2000
/* my own buf 32k */
#define DMX_BUF_SZ 0x8000
#else
/* ffmpeg buf 2k */ /* ffmpeg buf 2k */
#define INBUF_SIZE 0x0800 #define INBUF_SIZE 0x0800
/* my own buf 16k */ /* my own buf 16k */
#define DMX_BUF_SZ 0x4000 #define DMX_BUF_SZ 0x4000
#endif
cAudio * audioDecoder = NULL; cAudio * audioDecoder = NULL;
extern cDemux *audioDemux; extern cDemux *audioDemux;
@@ -68,6 +55,8 @@ static cAudio *gThiz = NULL;
static ao_device *adevice = NULL; static ao_device *adevice = NULL;
static ao_sample_format sformat; static ao_sample_format sformat;
static AVCodecContext *c= NULL;
cAudio::cAudio(void *, void *, void *) cAudio::cAudio(void *, void *, void *)
{ {
thread_started = false; thread_started = false;
@@ -113,22 +102,22 @@ int cAudio::setVolume(unsigned int left, unsigned int right)
int cAudio::Start(void) int cAudio::Start(void)
{ {
lt_info("%s >\n", __func__); lt_debug("%s >\n", __func__);
if (! HAL_nodec) if (! HAL_nodec)
OpenThreads::Thread::start(); OpenThreads::Thread::start();
lt_info("%s <\n", __func__); lt_debug("%s <\n", __func__);
return 0; return 0;
} }
int cAudio::Stop(void) int cAudio::Stop(void)
{ {
lt_info("%s >\n", __func__); lt_debug("%s >\n", __func__);
if (thread_started) if (thread_started)
{ {
thread_started = false; thread_started = false;
OpenThreads::Thread::join(); OpenThreads::Thread::join();
} }
lt_info("%s <\n", __func__); lt_debug("%s <\n", __func__);
return 0; return 0;
} }
@@ -207,12 +196,51 @@ int cAudio::StopClip()
void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode) void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode)
{ {
lt_debug("%s\n", __func__);
type = 0; type = 0;
layer = 0; layer = 0; /* not used */
freq = 0; freq = 0;
bitrate = 0; bitrate = 0; /* not used, but easy to get :-) */
mode = 0; mode = 0; /* default: stereo */
if (c) {
type = (c->codec_id != AV_CODEC_ID_MP2); /* only mpeg / not mpeg is indicated */
freq = c->sample_rate;
bitrate = c->bit_rate;
if (c->channels == 1)
mode = 3; /* for AV_CODEC_ID_MP2, only stereo / mono is detected for now */
if (c->codec_id != AV_CODEC_ID_MP2) {
switch (c->channel_layout) {
case AV_CH_LAYOUT_MONO:
mode = 1; // "C"
break;
case AV_CH_LAYOUT_STEREO:
mode = 2; // "L/R"
break;
case AV_CH_LAYOUT_2_1:
case AV_CH_LAYOUT_SURROUND:
mode = 3; // "L/C/R"
break;
case AV_CH_LAYOUT_2POINT1:
mode = 4; // "L/R/S"
break;
case AV_CH_LAYOUT_3POINT1:
mode = 5; // "L/C/R/S"
break;
case AV_CH_LAYOUT_2_2:
case AV_CH_LAYOUT_QUAD:
mode = 6; // "L/R/SL/SR"
break;
case AV_CH_LAYOUT_5POINT0:
case AV_CH_LAYOUT_5POINT1:
mode = 7; // "L/C/R/SL/SR"
break;
default:
lt_info("%s: unknown ch_layout 0x%" PRIx64 "\n",
__func__, c->channel_layout);
}
}
}
lt_debug("%s t: %d l: %d f: %d b: %d m: %d codec_id: %x\n",
__func__, type, layer, freq, bitrate, mode, c->codec_id);
}; };
void cAudio::SetSRS(int /*iq_enable*/, int /*nmgr_enable*/, int /*iq_mode*/, int /*iq_level*/) void cAudio::SetSRS(int /*iq_enable*/, int /*nmgr_enable*/, int /*iq_mode*/, int /*iq_level*/)
@@ -284,7 +312,6 @@ void cAudio::run()
av_register_all(); av_register_all();
AVCodec *codec; AVCodec *codec;
AVCodecContext *c= NULL;
AVFormatContext *avfc = NULL; AVFormatContext *avfc = NULL;
AVInputFormat *inp; AVInputFormat *inp;
AVFrame *frame; AVFrame *frame;
@@ -295,14 +322,14 @@ void cAudio::run()
ao_info *ai; ao_info *ai;
// ao_device *adevice; // ao_device *adevice;
// ao_sample_format sformat; // ao_sample_format sformat;
#ifdef MARTII /* resample */
#ifdef USE_LIBSWRESAMPLE
SwrContext *swr = NULL; SwrContext *swr = NULL;
#else uint8_t *obuf = NULL;
AVAudioResampleContext *avr = NULL; int obuf_sz = 0; /* in samples */
#endif int obuf_sz_max = 0;
int e; int o_ch, o_sr; /* output channels and sample rate */
#endif uint64_t o_layout; /* output channels layout */
char tmp[64] = "unknown";
curr_pts = 0; curr_pts = 0;
av_init_packet(&avpkt); av_init_packet(&avpkt);
@@ -336,7 +363,7 @@ void cAudio::run()
c = avfc->streams[0]->codec; c = avfc->streams[0]->codec;
codec = avcodec_find_decoder(c->codec_id); codec = avcodec_find_decoder(c->codec_id);
if (!codec) { if (!codec) {
lt_info("%s: Codec not found\n", __func__); lt_info("%s: Codec for %s not found\n", __func__, avcodec_get_name(c->codec_id));
goto out; goto out;
} }
if (avcodec_open2(c, codec, NULL) < 0) { if (avcodec_open2(c, codec, NULL) < 0) {
@@ -348,13 +375,17 @@ void cAudio::run()
lt_info("%s: avcodec_alloc_frame failed\n", __func__); lt_info("%s: avcodec_alloc_frame failed\n", __func__);
goto out2; goto out2;
} }
if (sformat.channels != c->channels || sformat.rate != c->sample_rate || /* output sample rate, channels, layout could be set here if necessary */
o_ch = c->channels; /* 2 */
o_sr = c->sample_rate; /* 48000 */
o_layout = c->channel_layout; /* AV_CH_LAYOUT_STEREO */
if (sformat.channels != o_ch || sformat.rate != o_sr ||
sformat.byte_format != AO_FMT_NATIVE || sformat.bits != 16 || adevice == NULL) sformat.byte_format != AO_FMT_NATIVE || sformat.bits != 16 || adevice == NULL)
{ {
driver = ao_default_driver_id(); driver = ao_default_driver_id();
sformat.bits = 16; sformat.bits = 16;
sformat.channels = c->channels; sformat.channels = o_ch;
sformat.rate = c->sample_rate; sformat.rate = o_sr;
sformat.byte_format = AO_FMT_NATIVE; sformat.byte_format = AO_FMT_NATIVE;
sformat.matrix = 0; sformat.matrix = 0;
if (adevice) if (adevice)
@@ -362,7 +393,7 @@ void cAudio::run()
adevice = ao_open_live(driver, &sformat, NULL); adevice = ao_open_live(driver, &sformat, NULL);
ai = ao_driver_info(driver); ai = ao_driver_info(driver);
lt_info("%s: changed params ch %d srate %d bits %d adevice %p\n", lt_info("%s: changed params ch %d srate %d bits %d adevice %p\n",
__func__, c->channels, c->sample_rate, 16, adevice);; __func__, o_ch, o_sr, 16, adevice);;
lt_info("libao driver: %d name '%s' short '%s' author '%s'\n", lt_info("libao driver: %d name '%s' short '%s' author '%s'\n",
driver, ai->name, ai->short_name, ai->author); driver, ai->name, ai->short_name, ai->author);
} }
@@ -372,95 +403,57 @@ void cAudio::run()
fprintf(stderr, " %s", ai->options[i]); fprintf(stderr, " %s", ai->options[i]);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif
#ifdef MARTII av_get_sample_fmt_string(tmp, sizeof(tmp), c->sample_fmt);
# ifdef USE_LIBSWRESAMPLE lt_info("decoding %s, sample_fmt %d (%s) sample_rate %d channels %d\n",
swr = swr_alloc(); avcodec_get_name(c->codec_id), c->sample_fmt, tmp, c->sample_rate, c->channels);
av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0); swr = swr_alloc_set_opts(swr,
av_opt_set_int(swr, "out_channel_layout", c->channel_layout, 0); o_layout, AV_SAMPLE_FMT_S16, o_sr, /* output */
av_opt_set_int(swr, "in_sample_rate", c->sample_rate, 0); c->channel_layout, c->sample_fmt, c->sample_rate, /* input */
av_opt_set_int(swr, "out_sample_rate", c->sample_rate, 0); 0, NULL);
av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, 0); if (! swr) {
av_opt_set_int(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); lt_info("could not alloc resample context\n");
e = swr_init(swr); goto out3;
if (e < 0) {
lt_info("%s: swr_init failed: %d\n", __func__, -e);
goto out2;
} }
# else swr_init(swr);
avr = avresample_alloc_context();
av_opt_set_int(avr, "in_channel_layout", c->channel_layout, 0);
av_opt_set_int(avr, "out_channel_layout", c->channel_layout, 0);
av_opt_set_int(avr, "in_sample_rate", c->sample_rate, 0);
av_opt_set_int(avr, "out_sample_rate", c->sample_rate, 0);
av_opt_set_int(avr, "in_sample_fmt", c->sample_fmt, 0);
av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
e = avresample_open(avr);
if (e < 0) {
lt_info("%s: avresample_open failed: %d\n", __func__, -e);
goto out2;
}
# endif
#endif
lt_info("codec params: sample_fmt %d sample_rate %d channels %d\n",
c->sample_fmt, c->sample_rate, c->channels);
while (thread_started) { while (thread_started) {
int gotframe = 0; int gotframe = 0;
if (av_read_frame(avfc, &avpkt) < 0) if (av_read_frame(avfc, &avpkt) < 0)
break; break;
avcodec_decode_audio4(c, frame, &gotframe, &avpkt); avcodec_decode_audio4(c, frame, &gotframe, &avpkt);
if (gotframe && thread_started) { if (gotframe && thread_started) {
int out_linesize;
obuf_sz = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) +
frame->nb_samples, o_sr, c->sample_rate, AV_ROUND_UP);
if (obuf_sz > obuf_sz_max) {
lt_info("obuf_sz: %d old: %d\n", obuf_sz, obuf_sz_max);
av_free(obuf);
if (av_samples_alloc(&obuf, &out_linesize, o_ch,
frame->nb_samples, AV_SAMPLE_FMT_S16, 1) < 0) {
lt_info("av_samples_alloc failed\n");
av_free_packet(&avpkt);
break; /* while (thread_started) */
}
obuf_sz_max = obuf_sz;
}
obuf_sz = swr_convert(swr, &obuf, obuf_sz,
(const uint8_t **)frame->extended_data, frame->nb_samples);
curr_pts = av_frame_get_best_effort_timestamp(frame); curr_pts = av_frame_get_best_effort_timestamp(frame);
lt_debug("%s: pts 0x%" PRIx64 " %3f\n", __func__, curr_pts, curr_pts/90000.0); lt_debug("%s: pts 0x%" PRIx64 " %3f\n", __func__, curr_pts, curr_pts/90000.0);
#ifdef MARTII int o_buf_sz = av_samples_get_buffer_size(&out_linesize, o_ch,
uint8_t *output = NULL; obuf_sz, AV_SAMPLE_FMT_S16, 1);
# ifdef USE_LIBSWRESAMPLE ao_play(adevice, (char *)obuf, o_buf_sz);
int out_samples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + frame->nb_samples,
c->sample_rate, c->sample_rate, AV_ROUND_UP);
e = av_samples_alloc(&output, NULL, c->channels, out_samples, AV_SAMPLE_FMT_S16, 1);
if (e < 0) {
lt_info("%s: av_samples_alloc failed: %d\n", __func__, -e);
goto out2;
}
out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **) &frame->data[0], frame->nb_samples);
# else
uint8_t *output = NULL;
int out_linesize;
int out_samples = avresample_available(avr)
+ av_rescale_rnd(avresample_get_delay(avr) + frame->nb_samples,
c->sample_rate, c->sample_rate, AV_ROUND_UP);
e = av_samples_alloc(&output, &out_linesize, c->channels, out_samples, AV_SAMPLE_FMT_S16, 1);
if (e < 0) {
lt_info("%s: av_samples_alloc failed: %d\n", __func__, -e);
goto out2;
}
out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
&frame->data[0], frame->linesize[0], frame->nb_samples);
# endif
ao_play(adevice, (char *)output, out_samples * 2 /* 16 bit */ * c->channels);
av_freep(&output);
#else
ao_play(adevice, (char*)frame->extended_data[0], frame->linesize[0]);
#endif
} }
av_free_packet(&avpkt); av_free_packet(&avpkt);
} }
// ao_close(adevice); /* can take long :-( */ // ao_close(adevice); /* can take long :-( */
av_free(obuf);
swr_free(&swr);
out3:
avcodec_free_frame(&frame); avcodec_free_frame(&frame);
out2: out2:
avcodec_close(c); avcodec_close(c);
c = NULL;
out: out:
#ifdef MARTII
# ifdef USE_LIBSWRESAMPLE
if (swr) {
swr_free(&swr);
}
# else
if (avr) {
avresample_close(avr);
avresample_free(&avr);
}
# endif
#endif
avformat_close_input(&avfc); avformat_close_input(&avfc);
av_free(pIOCtx->buffer); av_free(pIOCtx->buffer);
av_free(pIOCtx); av_free(pIOCtx);

View File

@@ -40,6 +40,8 @@ void init_td_api()
* valgrind-check other parts... export HAL_NOAVDEC=1 */ * valgrind-check other parts... export HAL_NOAVDEC=1 */
if (getenv("HAL_NOAVDEC")) if (getenv("HAL_NOAVDEC"))
HAL_nodec = true; HAL_nodec = true;
/* hack, this triggers that the simple_display thread does not blit() once per second... */
setenv("SPARK_NOBLIT", "1", 1);
initialized = true; initialized = true;
} }

View File

@@ -139,21 +139,21 @@ int cVideo::setCroppingMode(int)
int cVideo::Start(void *, unsigned short, unsigned short, void *) int cVideo::Start(void *, unsigned short, unsigned short, void *)
{ {
lt_info("%s running %d >\n", __func__, thread_running); lt_debug("%s running %d >\n", __func__, thread_running);
if (!thread_running && !HAL_nodec) if (!thread_running && !HAL_nodec)
OpenThreads::Thread::start(); OpenThreads::Thread::start();
lt_info("%s running %d <\n", __func__, thread_running); lt_debug("%s running %d <\n", __func__, thread_running);
return 0; return 0;
} }
int cVideo::Stop(bool) int cVideo::Stop(bool)
{ {
lt_info("%s running %d >\n", __func__, thread_running); lt_debug("%s running %d >\n", __func__, thread_running);
if (thread_running) { if (thread_running) {
thread_running = false; thread_running = false;
OpenThreads::Thread::join(); OpenThreads::Thread::join();
} }
lt_info("%s running %d <\n", __func__, thread_running); lt_debug("%s running %d <\n", __func__, thread_running);
return 0; return 0;
} }
@@ -446,7 +446,6 @@ void cVideo::run(void)
if (! thread_running) if (! thread_running)
goto out; goto out;
} }
lt_info("%s: nb_streams %d\n", __func__, avfc->nb_streams);
if (avfc->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO) if (avfc->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO)
lt_info("%s: no video codec? 0x%x\n", __func__, avfc->streams[0]->codec->codec_type); lt_info("%s: no video codec? 0x%x\n", __func__, avfc->streams[0]->codec->codec_type);
@@ -454,7 +453,7 @@ void cVideo::run(void)
c = avfc->streams[0]->codec; c = avfc->streams[0]->codec;
codec = avcodec_find_decoder(c->codec_id); codec = avcodec_find_decoder(c->codec_id);
if (!codec) { if (!codec) {
lt_info("%s: Codec not found\n", __func__); lt_info("%s: Codec for %s not found\n", __func__, avcodec_get_name(c->codec_id));
goto out; goto out;
} }
if (avcodec_open2(c, codec, NULL) < 0) { if (avcodec_open2(c, codec, NULL) < 0) {
@@ -467,6 +466,7 @@ void cVideo::run(void)
lt_info("%s: Could not allocate video frame\n", __func__); lt_info("%s: Could not allocate video frame\n", __func__);
goto out2; goto out2;
} }
lt_info("decoding %s\n", avcodec_get_name(c->codec_id));
while (thread_running) { while (thread_running) {
if (av_read_frame(avfc, &avpkt) < 0) { if (av_read_frame(avfc, &avpkt) < 0) {
if (warn_r - time(NULL) > 4) { if (warn_r - time(NULL) > 4) {

View File

@@ -5,7 +5,11 @@ INCLUDES = \
noinst_LTLIBRARIES = libspark.la noinst_LTLIBRARIES = libspark.la
AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing
AM_LDFLAGS = -lpthread -lasound AM_LDFLAGS = -lpthread -lasound -lass \
@AVFORMAT_LIBS@ \
@AVUTIL_LIBS@ \
@AVCODEC_LIBS@ \
@SWRESAMPLE_LIBS@
libspark_la_SOURCES = \ libspark_la_SOURCES = \
hardware_caps.c \ hardware_caps.c \
@@ -18,4 +22,4 @@ libspark_la_SOURCES = \
pwrmngr.cpp \ pwrmngr.cpp \
record.cpp record.cpp
AM_CPPFLAGS = -DF_INTERRUPTS=20000 -DIRMP_EMBED -DLIRC_IRMP #AM_CPPFLAGS = -DF_INTERRUPTS=20000 -DIRMP_EMBED -DLIRC_IRMP

View File

@@ -5,6 +5,8 @@ INCLUDES = \
noinst_LTLIBRARIES = libtriple.la noinst_LTLIBRARIES = libtriple.la
AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing
AM_LDFLAGS = \
@DIRECTFB_LIBS@
libtriple_la_SOURCES = \ libtriple_la_SOURCES = \
hardware_caps.c \ hardware_caps.c \