mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-26 23:13:16 +02:00
libeplayer3: cleanup pcm writer
This commit is contained in:
@@ -148,26 +148,6 @@ static const char *Codec2Encoding(AVCodecContext * codec)
|
|||||||
return "A_EAC3";
|
return "A_EAC3";
|
||||||
case AV_CODEC_ID_DTS:
|
case AV_CODEC_ID_DTS:
|
||||||
return "A_DTS";
|
return "A_DTS";
|
||||||
#if 0
|
|
||||||
case AV_CODEC_ID_AAC:
|
|
||||||
return "A_AAC";
|
|
||||||
case AV_CODEC_ID_WMAV1:
|
|
||||||
case AV_CODEC_ID_WMAV2:
|
|
||||||
case AV_CODEC_ID_WMAPRO:
|
|
||||||
return "A_WMA";
|
|
||||||
case AV_CODEC_ID_MLP:
|
|
||||||
return "A_MLP";
|
|
||||||
case AV_CODEC_ID_RA_144:
|
|
||||||
return "A_RMA";
|
|
||||||
case AV_CODEC_ID_RA_288:
|
|
||||||
return "A_RMA";
|
|
||||||
case AV_CODEC_ID_VORBIS:
|
|
||||||
return "A_VORBIS";
|
|
||||||
case AV_CODEC_ID_FLAC:
|
|
||||||
return return "A_FLAC";
|
|
||||||
case AV_CODEC_ID_PCM_S16LE:
|
|
||||||
return "A_PCM";
|
|
||||||
#endif
|
|
||||||
/* subtitle */
|
/* subtitle */
|
||||||
case AV_CODEC_ID_SSA:
|
case AV_CODEC_ID_SSA:
|
||||||
return "S_TEXT/ASS"; /* Hellmaster1024: seems to be ASS instead of SSA */
|
return "S_TEXT/ASS"; /* Hellmaster1024: seems to be ASS instead of SSA */
|
||||||
|
BIN
libeplayer3/include/.writer.h.swp
Normal file
BIN
libeplayer3/include/.writer.h.swp
Normal file
Binary file not shown.
@@ -37,10 +37,6 @@ typedef enum {
|
|||||||
} OutputCmd_t;
|
} OutputCmd_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int uNoOfChannels;
|
|
||||||
int uSampleRate;
|
|
||||||
int uBitsPerSample;
|
|
||||||
int bLittleEndian;
|
|
||||||
int restart_audio_resampling;
|
int restart_audio_resampling;
|
||||||
|
|
||||||
int64_t pts;
|
int64_t pts;
|
||||||
|
@@ -20,10 +20,6 @@ typedef struct Context_s Context_t;
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
int64_t Pts;
|
int64_t Pts;
|
||||||
int uNoOfChannels;
|
|
||||||
int uSampleRate;
|
|
||||||
int uBitsPerSample;
|
|
||||||
int bLittleEndian;
|
|
||||||
int restart_audio_resampling;
|
int restart_audio_resampling;
|
||||||
AVFormatContext *avfc;
|
AVFormatContext *avfc;
|
||||||
AVStream *stream;
|
AVStream *stream;
|
||||||
|
@@ -976,10 +976,6 @@ static int Write(Context_t *context, AudioVideoOut_t *out)
|
|||||||
call.Pts = out->pts;
|
call.Pts = out->pts;
|
||||||
call.packet = out->packet;
|
call.packet = out->packet;
|
||||||
|
|
||||||
call.uNoOfChannels = out->uNoOfChannels;
|
|
||||||
call.uSampleRate = out->uSampleRate;
|
|
||||||
call.uBitsPerSample = out->uBitsPerSample;
|
|
||||||
call.bLittleEndian = out->bLittleEndian;
|
|
||||||
call.restart_audio_resampling = out->restart_audio_resampling;
|
call.restart_audio_resampling = out->restart_audio_resampling;
|
||||||
call.context = context;
|
call.context = context;
|
||||||
|
|
||||||
|
@@ -107,9 +107,11 @@ static unsigned int breakBufferFillSize = 0;
|
|||||||
/* MISC Functions */
|
/* MISC Functions */
|
||||||
/* ***************************** */
|
/* ***************************** */
|
||||||
|
|
||||||
static int prepareClipPlay(int uNoOfChannels, int uSampleRate,
|
static int uNoOfChannels;
|
||||||
int uBitsPerSample, int bLittleEndian
|
static int uSampleRate;
|
||||||
__attribute__ ((unused)))
|
static int uBitsPerSample;
|
||||||
|
|
||||||
|
static int prepareClipPlay()
|
||||||
{
|
{
|
||||||
printf("rate: %d ch: %d bits: %d (%d bps)\n",
|
printf("rate: %d ch: %d bits: %d (%d bps)\n",
|
||||||
uSampleRate /*Format->dwSamplesPerSec */ ,
|
uSampleRate /*Format->dwSamplesPerSec */ ,
|
||||||
@@ -177,34 +179,23 @@ static int prepareClipPlay(int uNoOfChannels, int uSampleRate,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reset()
|
|
||||||
{
|
|
||||||
initialHeader = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int writeData(WriterAVCallData_t *call)
|
static int writePCM(int fd, int64_t Pts, uint8_t *data, unsigned int size)
|
||||||
{
|
{
|
||||||
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
|
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
|
||||||
|
|
||||||
pcm_printf(10, "AudioPts %lld\n", call->Pts);
|
pcm_printf(10, "AudioPts %lld\n", Pts);
|
||||||
|
|
||||||
if (call->fd < 0) {
|
if (fd < 0) {
|
||||||
pcm_err("file pointer < 0. ignoring ...\n");
|
pcm_err("file pointer < 0. ignoring ...\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialHeader) {
|
if (initialHeader) {
|
||||||
initialHeader = 0;
|
initialHeader = 0;
|
||||||
prepareClipPlay(call->uNoOfChannels,
|
prepareClipPlay();
|
||||||
call->uSampleRate,
|
|
||||||
call->uBitsPerSample,
|
|
||||||
call->bLittleEndian);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *buffer = call->packet->data;
|
|
||||||
unsigned int size = call->packet->size;
|
|
||||||
|
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
unsigned char *injectBuffer = (unsigned char *) malloc(SubFrameLen);
|
unsigned char *injectBuffer = (unsigned char *) malloc(SubFrameLen);
|
||||||
unsigned int pos;
|
unsigned int pos;
|
||||||
@@ -213,7 +204,7 @@ static int writeData(WriterAVCallData_t *call)
|
|||||||
//printf("PCM %s - Position=%d\n", __FUNCTION__, pos);
|
//printf("PCM %s - Position=%d\n", __FUNCTION__, pos);
|
||||||
if ((size - pos) < SubFrameLen) {
|
if ((size - pos) < SubFrameLen) {
|
||||||
breakBufferFillSize = size - pos;
|
breakBufferFillSize = size - pos;
|
||||||
memcpy(breakBuffer, &buffer[pos],
|
memcpy(breakBuffer, &data[pos],
|
||||||
sizeof(unsigned char) * breakBufferFillSize);
|
sizeof(unsigned char) * breakBufferFillSize);
|
||||||
//printf("PCM %s - Unplayed=%d\n", __FUNCTION__, breakBufferFillSize);
|
//printf("PCM %s - Unplayed=%d\n", __FUNCTION__, breakBufferFillSize);
|
||||||
break;
|
break;
|
||||||
@@ -221,11 +212,11 @@ static int writeData(WriterAVCallData_t *call)
|
|||||||
//get first PES's worth
|
//get first PES's worth
|
||||||
if (breakBufferFillSize > 0) {
|
if (breakBufferFillSize > 0) {
|
||||||
memcpy(injectBuffer, breakBuffer, sizeof(unsigned char) * breakBufferFillSize);
|
memcpy(injectBuffer, breakBuffer, sizeof(unsigned char) * breakBufferFillSize);
|
||||||
memcpy(&injectBuffer[breakBufferFillSize], &buffer[pos], sizeof(unsigned char) * (SubFrameLen - breakBufferFillSize));
|
memcpy(&injectBuffer[breakBufferFillSize], &data[pos], sizeof(unsigned char) * (SubFrameLen - breakBufferFillSize));
|
||||||
pos += (SubFrameLen - breakBufferFillSize);
|
pos += (SubFrameLen - breakBufferFillSize);
|
||||||
breakBufferFillSize = 0;
|
breakBufferFillSize = 0;
|
||||||
} else {
|
} else {
|
||||||
memcpy(injectBuffer, &buffer[pos], sizeof(unsigned char) * SubFrameLen);
|
memcpy(injectBuffer, &data[pos], sizeof(unsigned char) * SubFrameLen);
|
||||||
pos += SubFrameLen;
|
pos += SubFrameLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +229,7 @@ static int writeData(WriterAVCallData_t *call)
|
|||||||
iov[2].iov_len = SubFrameLen;
|
iov[2].iov_len = SubFrameLen;
|
||||||
|
|
||||||
//write the PCM data
|
//write the PCM data
|
||||||
if (call->uBitsPerSample == 16) {
|
if (uBitsPerSample == 16) {
|
||||||
for (n = 0; n < SubFrameLen; n += 2) {
|
for (n = 0; n < SubFrameLen; n += 2) {
|
||||||
unsigned char tmp;
|
unsigned char tmp;
|
||||||
tmp = injectBuffer[n];
|
tmp = injectBuffer[n];
|
||||||
@@ -267,8 +258,8 @@ static int writeData(WriterAVCallData_t *call)
|
|||||||
//increment err... subframe count?
|
//increment err... subframe count?
|
||||||
lpcm_prv[1] = ((lpcm_prv[1] + SubFramesPerPES) & 0x1F);
|
lpcm_prv[1] = ((lpcm_prv[1] + SubFramesPerPES) & 0x1F);
|
||||||
|
|
||||||
iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, PCM_PES_START_CODE, call->Pts, 0);
|
iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, PCM_PES_START_CODE, Pts, 0);
|
||||||
int len = writev(call->fd, iov, 3);
|
int len = writev(fd, iov, 3);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -285,8 +276,10 @@ int out_channels = 2;
|
|||||||
uint64_t out_channel_layout = AV_CH_LAYOUT_STEREO;
|
uint64_t out_channel_layout = AV_CH_LAYOUT_STEREO;
|
||||||
int restart_audio_resampling = 0;
|
int restart_audio_resampling = 0;
|
||||||
|
|
||||||
static int resetIpcm()
|
static int reset()
|
||||||
{
|
{
|
||||||
|
initialHeader = 1;
|
||||||
|
|
||||||
if (swr) {
|
if (swr) {
|
||||||
swr_free(&swr);
|
swr_free(&swr);
|
||||||
swr = NULL; //FIXME: Needed?
|
swr = NULL; //FIXME: Needed?
|
||||||
@@ -301,7 +294,7 @@ static int resetIpcm()
|
|||||||
|
|
||||||
int64_t calcPts(AVFormatContext *, AVStream *, int64_t);
|
int64_t calcPts(AVFormatContext *, AVStream *, int64_t);
|
||||||
|
|
||||||
static int writeDataIpcm(WriterAVCallData_t *call)
|
static int writeData(WriterAVCallData_t *call)
|
||||||
{
|
{
|
||||||
AVCodecContext *c = call->stream->codec;
|
AVCodecContext *c = call->stream->codec;
|
||||||
AVPacket *packet = call->packet;
|
AVPacket *packet = call->packet;
|
||||||
@@ -309,18 +302,12 @@ static int writeDataIpcm(WriterAVCallData_t *call)
|
|||||||
unsigned int packet_size = packet->size;
|
unsigned int packet_size = packet->size;
|
||||||
|
|
||||||
if (call->restart_audio_resampling)
|
if (call->restart_audio_resampling)
|
||||||
call->restart_audio_resampling = 1;
|
restart_audio_resampling = 1;
|
||||||
|
|
||||||
if (restart_audio_resampling) {
|
if (restart_audio_resampling) {
|
||||||
restart_audio_resampling = 0;
|
restart_audio_resampling = 0;
|
||||||
if (swr) {
|
reset();
|
||||||
swr_free(&swr);
|
|
||||||
swr = NULL;
|
|
||||||
}
|
|
||||||
if (decoded_frame) {
|
|
||||||
av_frame_free(&decoded_frame);
|
|
||||||
decoded_frame = NULL;
|
|
||||||
}
|
|
||||||
call->context->output->Command(call->context, OUTPUT_CLEAR, NULL);
|
call->context->output->Command(call->context, OUTPUT_CLEAR, NULL);
|
||||||
call->context->output->Command(call->context, OUTPUT_PLAY, NULL);
|
call->context->output->Command(call->context, OUTPUT_PLAY, NULL);
|
||||||
|
|
||||||
@@ -328,17 +315,17 @@ static int writeDataIpcm(WriterAVCallData_t *call)
|
|||||||
|
|
||||||
if (!codec || avcodec_open2(c, codec, NULL))
|
if (!codec || avcodec_open2(c, codec, NULL))
|
||||||
fprintf(stderr, "%s %d: avcodec_open2 failed\n", __func__, __LINE__);
|
fprintf(stderr, "%s %d: avcodec_open2 failed\n", __func__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (packet_size > 0) {
|
while (packet_size > 0) {
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
if (!decoded_frame) {
|
if (!decoded_frame) {
|
||||||
if (!(decoded_frame = av_frame_alloc())) {
|
if (!(decoded_frame = av_frame_alloc())) {
|
||||||
fprintf(stderr, "out of memory\n");
|
fprintf(stderr, "out of memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
av_frame_unref(decoded_frame);
|
av_frame_unref(decoded_frame);
|
||||||
|
|
||||||
int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, packet);
|
int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, packet);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@@ -403,32 +390,19 @@ static int writeDataIpcm(WriterAVCallData_t *call)
|
|||||||
// FIXME. PTS calculation is probably broken.
|
// FIXME. PTS calculation is probably broken.
|
||||||
int64_t pts;
|
int64_t pts;
|
||||||
int64_t next_in_pts = av_rescale(av_frame_get_best_effort_timestamp(decoded_frame),
|
int64_t next_in_pts = av_rescale(av_frame_get_best_effort_timestamp(decoded_frame),
|
||||||
call->stream->time_base.num * (int64_t) out_sample_rate * c->sample_rate,
|
call->stream->time_base.num * (int64_t) out_sample_rate * c->sample_rate,
|
||||||
call->stream->time_base.den);
|
call->stream->time_base.den);
|
||||||
int64_t next_out_pts = av_rescale(swr_next_pts(swr, next_in_pts),
|
int64_t next_out_pts = av_rescale(swr_next_pts(swr, next_in_pts),
|
||||||
call->stream->time_base.den,
|
call->stream->time_base.den,
|
||||||
call->stream->time_base.num * (int64_t) out_sample_rate * c->sample_rate);
|
call->stream->time_base.num * (int64_t) out_sample_rate * c->sample_rate);
|
||||||
*(call->context->currentAudioPtsP) = /* audioTrack->pts = */ pts = calcPts(call->avfc, call->stream, next_out_pts);
|
*(call->context->currentAudioPtsP) = /* audioTrack->pts = */ pts = calcPts(call->avfc, call->stream, next_out_pts);
|
||||||
out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **)
|
out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **) &decoded_frame->data[0], in_samples);
|
||||||
&decoded_frame->data[0], in_samples);
|
|
||||||
|
|
||||||
WriterAVCallData_t pcmOut;
|
uSampleRate = out_sample_rate;
|
||||||
pcmOut.fd = call->fd;
|
uNoOfChannels = av_get_channel_layout_nb_channels(out_channel_layout);
|
||||||
pcmOut.uSampleRate = out_sample_rate;
|
uBitsPerSample = 16;
|
||||||
pcmOut.uNoOfChannels = av_get_channel_layout_nb_channels(out_channel_layout);
|
|
||||||
pcmOut.uBitsPerSample = 16;
|
|
||||||
pcmOut.bLittleEndian = 1;
|
|
||||||
|
|
||||||
AVPacket pcmPacket;
|
writePCM(call->fd, pts, output, out_samples * sizeof(short) * out_channels);
|
||||||
pcmPacket.data = output;
|
|
||||||
pcmPacket.size = out_samples * sizeof(short) * out_channels;
|
|
||||||
pcmOut.packet = &pcmPacket;
|
|
||||||
|
|
||||||
pcmOut.Pts = pts; // FIXME videoTrack ? pts : 0;
|
|
||||||
//pcmOut.stream = call->stream;
|
|
||||||
//pcmOut.avfc = call->avfc;
|
|
||||||
|
|
||||||
writeData(&pcmOut);
|
|
||||||
|
|
||||||
av_freep(&output);
|
av_freep(&output);
|
||||||
}
|
}
|
||||||
@@ -439,20 +413,6 @@ static int writeDataIpcm(WriterAVCallData_t *call)
|
|||||||
/* Writer Definition */
|
/* Writer Definition */
|
||||||
/* ***************************** */
|
/* ***************************** */
|
||||||
|
|
||||||
static WriterCaps_t caps_pcm = {
|
|
||||||
"pcm",
|
|
||||||
eAudio,
|
|
||||||
"A_PCM",
|
|
||||||
AUDIO_ENCODING_LPCMA
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Writer_s WriterAudioPCM = {
|
|
||||||
&reset,
|
|
||||||
&writeData,
|
|
||||||
NULL,
|
|
||||||
&caps_pcm
|
|
||||||
};
|
|
||||||
|
|
||||||
static WriterCaps_t caps_ipcm = {
|
static WriterCaps_t caps_ipcm = {
|
||||||
"ipcm",
|
"ipcm",
|
||||||
eAudio,
|
eAudio,
|
||||||
@@ -461,8 +421,8 @@ static WriterCaps_t caps_ipcm = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Writer_s WriterAudioIPCM = {
|
struct Writer_s WriterAudioIPCM = {
|
||||||
&resetIpcm,
|
&reset,
|
||||||
&writeDataIpcm,
|
&writeData,
|
||||||
NULL,
|
NULL,
|
||||||
&caps_ipcm
|
&caps_ipcm
|
||||||
};
|
};
|
||||||
|
@@ -191,7 +191,7 @@ static int writeData(WriterAVCallData_t *call)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (call->packet->size > 0 && call->packet->data) {
|
if (call->packet->size > 0 && call->packet->data) {
|
||||||
unsigned int Position = 0;
|
int Position = 0;
|
||||||
unsigned char insertSampleHeader = 1;
|
unsigned char insertSampleHeader = 1;
|
||||||
while (Position < call->packet->size) {
|
while (Position < call->packet->size) {
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ if (debug_level >= level) printf(x); } while (0)
|
|||||||
|
|
||||||
static Writer_t *AvailableWriter[] = {
|
static Writer_t *AvailableWriter[] = {
|
||||||
&WriterAudioIPCM,
|
&WriterAudioIPCM,
|
||||||
&WriterAudioPCM,
|
// &WriterAudioPCM,
|
||||||
&WriterAudioMP3,
|
&WriterAudioMP3,
|
||||||
&WriterAudioMPEGL3,
|
&WriterAudioMPEGL3,
|
||||||
&WriterAudioAC3,
|
&WriterAudioAC3,
|
||||||
|
Reference in New Issue
Block a user