formatting code using astyle

Origin commit data
------------------
Branch: master
Commit: bc17c13de4
Author: vanhofen <vanhofen@gmx.de>
Date: 2021-05-17 (Mon, 17 May 2021)

Origin message was:
------------------
- formatting code using astyle

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

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2021-05-17 23:47:39 +02:00
parent 7335985023
commit f54b0e7bec
161 changed files with 13025 additions and 11357 deletions

View File

@@ -43,18 +43,19 @@ extern "C" {
}
// reference: search for TypeLpcmDVDAudio in player/frame_parser/frame_parser_audio_lpcm.cpp
static const uint8_t clpcm_prv[14] = {
0xA0, //sub_stream_id
0, 0, //resvd and UPC_EAN_ISRC stuff, unused
0x0A, //private header length
0, 9, //first_access_unit_pointer
0x00, //emph,rsvd,stereo,downmix
0x0F, //quantisation word length 1,2
0x0F, //audio sampling freqency 1,2
0, //resvd, multi channel type
0, //bit shift on channel GR2, assignment
0x80, //dynamic range control
0, 0 //resvd for copyright management
static const uint8_t clpcm_prv[14] =
{
0xA0, //sub_stream_id
0, 0, //resvd and UPC_EAN_ISRC stuff, unused
0x0A, //private header length
0, 9, //first_access_unit_pointer
0x00, //emph,rsvd,stereo,downmix
0x0F, //quantisation word length 1,2
0x0F, //audio sampling freqency 1,2
0, //resvd, multi channel type
0, //bit shift on channel GR2, assignment
0x80, //dynamic range control
0, 0 //resvd for copyright management
};
class WriterPCM : public Writer
@@ -98,7 +99,8 @@ bool WriterPCM::prepareClipPlay()
memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv));
// figure out size of subframe and set up sample rate
switch (uSampleRate) {
switch (uSampleRate)
{
case 48000:
SubFrameLen = 40;
break;
@@ -136,7 +138,8 @@ bool WriterPCM::prepareClipPlay()
//set number of channels
lpcm_prv[10] = uNoOfChannels - 1;
switch (uBitsPerSample) {
switch (uBitsPerSample)
{
case 24:
lpcm_prv[7] |= 0x20;
case 16:
@@ -154,7 +157,8 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size)
bool res = true;
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
if (initialHeader) {
if (initialHeader)
{
initialHeader = false;
prepareClipPlay();
ioctl(fd, AUDIO_CLEAR_BUFFER, NULL);
@@ -162,7 +166,8 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size)
size += breakBufferFillSize;
while (size >= SubFrameLen) {
while (size >= SubFrameLen)
{
if (breakBufferFillSize)
memcpy(injectBuffer, breakBuffer, breakBufferFillSize);
memcpy(injectBuffer + breakBufferFillSize, data, SubFrameLen - breakBufferFillSize);
@@ -171,17 +176,22 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size)
breakBufferFillSize = 0;
//write the PCM data
if (uBitsPerSample == 16) {
for (unsigned int n = 0; n < SubFrameLen; n += 2) {
if (uBitsPerSample == 16)
{
for (unsigned int n = 0; n < SubFrameLen; n += 2)
{
uint8_t tmp = injectBuffer[n];
injectBuffer[n] = injectBuffer[n + 1];
injectBuffer[n + 1] = tmp;
}
} else {
}
else
{
// 0 1 2 3 4 5 6 7 8 9 10 11
// A1c A1b A1a B1c B1b B1a A2c A2b A2a B2c B2b B2a
// to A1a A1b B1a B1b A2a A2b B2a B2b A1c B1c A2c B2c
for (unsigned int n = 0; n < SubFrameLen; n += 12) {
for (unsigned int n = 0; n < SubFrameLen; n += 12)
{
uint8_t t, *p = injectBuffer + n;
t = p[0];
p[0] = p[2];
@@ -207,12 +217,14 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size)
iov[2].iov_len = SubFrameLen;
iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, PCM_PES_START_CODE, Pts, 0);
int len = writev(fd, iov, 3);
if (len < 0) {
if (len < 0)
{
res = false;
break;
}
}
if (size && res) {
if (size && res)
{
breakBufferFillSize = size;
memcpy(breakBuffer, data, size);
}
@@ -231,58 +243,67 @@ void WriterPCM::Init(int _fd, AVStream *_stream, Player *_player)
bool WriterPCM::Write(AVPacket *packet, int64_t pts)
{
if (!packet) {
if (!packet)
{
restart_audio_resampling = true;
return true;
}
AVCodecContext *c = player->input.GetCodecContext((unsigned int)stream->index);
if (restart_audio_resampling) {
if (restart_audio_resampling)
{
restart_audio_resampling = false;
initialHeader = true;
if (swr) {
if (swr)
{
swr_free(&swr);
swr = NULL;
}
if (decoded_frame) {
if (decoded_frame)
{
av_frame_free(&decoded_frame);
decoded_frame = NULL;
}
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57,25,101)
AVCodec *codec = avcodec_find_decoder(c->codec_id);
if (!codec) {
if (!codec)
{
fprintf(stderr, "%s %d: avcodec_find_decoder(%llx)\n", __func__, __LINE__, (unsigned long long) c->codec_id);
return false;
}
avcodec_close(c);
if (avcodec_open2(c, codec, NULL)) {
if (avcodec_open2(c, codec, NULL))
{
fprintf(stderr, "%s %d: avcodec_open2 failed\n", __func__, __LINE__);
return false;
}
#endif
}
if (!swr) {
if (!swr)
{
int in_rate = c->sample_rate;
// rates in descending order
int rates[] = {192000, 176400, 96000, 88200, 48000, 44100, 0};
int i = 0;
// find the next equal or smallest rate
while (rates[i] && in_rate < rates[i])
i++;
i++;
out_sample_rate = rates[i] ? rates[i] : 44100;
out_channels = c->channels;
if (c->channel_layout == 0) {
if (c->channel_layout == 0)
{
// FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder
c->channel_layout = AV_CH_LAYOUT_STEREO;
}
out_channel_layout = c->channel_layout;
// player2 won't play mono
if (out_channel_layout == AV_CH_LAYOUT_MONO) {
if (out_channel_layout == AV_CH_LAYOUT_MONO)
{
out_channel_layout = AV_CH_LAYOUT_STEREO;
out_channels = 2;
}
@@ -292,7 +313,8 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts)
uBitsPerSample = 16;
swr = swr_alloc();
if (!swr) {
if (!swr)
{
fprintf(stderr, "%s %d: swr_alloc failed\n", __func__, __LINE__);
return false;
}
@@ -304,31 +326,37 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts)
av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
int e = swr_init(swr);
if (e < 0) {
if (e < 0)
{
fprintf(stderr, "swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d)\n",
-e, (int) c->channel_layout,
(int) out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16);
-e, (int) c->channel_layout,
(int) out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16);
restart_audio_resampling = true;
return false;
}
}
unsigned int packet_size = packet->size;
while (packet_size > 0 || (!packet_size && !packet->data)) {
while (packet_size > 0 || (!packet_size && !packet->data))
{
if (!decoded_frame) {
if (!(decoded_frame = av_frame_alloc())) {
if (!decoded_frame)
{
if (!(decoded_frame = av_frame_alloc()))
{
fprintf(stderr, "out of memory\n");
exit(1);
}
} else
}
else
av_frame_unref(decoded_frame);
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100)
int got_frame = 0;
int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, packet);
if (len < 0) {
if (len < 0)
{
restart_audio_resampling = true;
break;
}
@@ -336,35 +364,43 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts)
if (packet->data)
packet_size -= len;
if (!got_frame) {
if (!got_frame)
{
if (!packet->data || !packet_size)
break;
continue;
}
#else
int ret = avcodec_send_packet(c, packet);
if (ret < 0) {
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
restart_audio_resampling = true;
break;
}
int ret = avcodec_send_packet(c, packet);
if (ret < 0)
{
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
{
restart_audio_resampling = true;
break;
}
if (ret >= 0) {
packet_size = 0;
}
if (ret >= 0)
{
packet_size = 0;
}
ret = avcodec_receive_frame(c, decoded_frame);
if (ret < 0)
{
if (ret == AVERROR_EOF)
{
restart_audio_resampling = true;
break;
}
ret = avcodec_receive_frame(c, decoded_frame);
if (ret < 0) {
if (ret == AVERROR_EOF) {
restart_audio_resampling = true;
break;
}
if (ret != AVERROR(EAGAIN)) {
break;
}
else {
continue;
}
if (ret != AVERROR(EAGAIN))
{
break;
}
else
{
continue;
}
}
#endif
#if (LIBAVUTIL_VERSION_MAJOR < 54)
@@ -375,11 +411,13 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts)
int in_samples = decoded_frame->nb_samples;
int out_samples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + in_samples, out_sample_rate, c->sample_rate, AV_ROUND_UP);
if (out_samples > out_samples_max) {
if (out_samples > out_samples_max)
{
if (output)
av_freep(&output);
int e = av_samples_alloc(&output, NULL, out_channels, out_samples, AV_SAMPLE_FMT_S16, 1);
if (e < 0) {
if (e < 0)
{
fprintf(stderr, "av_samples_alloc: %d\n", -e);
break;
}
@@ -388,7 +426,8 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts)
out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **) &decoded_frame->data[0], in_samples);
if (!writePCM(pts, output, out_samples * sizeof(short) * out_channels)) {
if (!writePCM(pts, output, out_samples * sizeof(short) * out_channels))
{
restart_audio_resampling = true;
break;
}
@@ -409,4 +448,4 @@ WriterPCM::WriterPCM()
Register(this, AV_CODEC_ID_INJECTPCM, AUDIO_ENCODING_LPCMA);
}
static WriterPCM writer_pcm __attribute__ ((init_priority (300)));
static WriterPCM writer_pcm __attribute__((init_priority(300)));