libeplayer3-arm: insert original blank lines from exteplayer3.git, for better merge

Origin commit data
------------------
Branch: master
Commit: 65de063d1e
Author: max_10 <max_10@gmx.de>
Date: 2018-04-10 (Tue, 10 Apr 2018)


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

------------------
This commit was generated by Migit
This commit is contained in:
max_10
2018-04-10 11:31:57 +02:00
parent d3d225ac35
commit 01d1fb6b28
79 changed files with 2070 additions and 117 deletions

View File

@@ -95,15 +95,19 @@ static void update_finish_timeout()
int64_t currPts = -1;
int32_t ret = g_context->playback->Command(g_context, PLAYBACK_PTS, &currPts);
finishTimeout += 1;
if (maxInjectedPts < 0 || maxInjectedPts == INVALID_PTS_VALUE)
{
maxInjectedPts = 0;
}
//printf("ret[%d] playPts[%lld] currPts[%lld] maxInjectedPts[%lld]\n", ret, playPts, currPts, maxInjectedPts);
/* On some STBs PTS readed from decoder is invalid after seek or at start
* this is the reason for additional validation when we what to close immediately
*/
if (!progressive_playback && 0 == ret && currPts >= maxInjectedPts && ((currPts - maxInjectedPts) / 90000) < 2)
if (!progressive_playback && 0 == ret && currPts >= maxInjectedPts &&
((currPts - maxInjectedPts) / 90000) < 2)
{
/* close immediately
*/
@@ -129,6 +133,7 @@ static int32_t ffmpeg_read_wrapper_base(void *opaque, uint8_t *buf, int32_t buf_
{
break;
}
int32_t partLen = ffmpeg_real_read_org(opaque, buf + len, buf_size - len);
if (partLen > 0)
{
@@ -141,7 +146,9 @@ static int32_t ffmpeg_read_wrapper_base(void *opaque, uint8_t *buf, int32_t buf_
len = 0;
break;
}
update_finish_timeout();
usleep(100000);
continue;
}
@@ -163,25 +170,31 @@ static int32_t ffmpeg_read_wrapper(void *opaque, uint8_t *buf, int32_t buf_size)
return ffmpeg_real_read_org(opaque, buf, buf_size);
}
}
#if 0
static int32_t ffmpeg_read_wrapper2(void *opaque, uint8_t *buf, int32_t buf_size)
{
return ffmpeg_read_wrapper_base(opaque, buf, buf_size, 1);
}
#endif
//for buffered io
void getfillerMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused)))
{
ffmpeg_printf(100, "::%d requesting mutex\n", line);
pthread_mutex_lock(&fillermutex);
ffmpeg_printf(100, "::%d received mutex\n", line);
}
void releasefillerMutex(const char *filename __attribute__((unused)), const const char *function __attribute__((unused)), int line __attribute__((unused)))
{
pthread_mutex_unlock(&fillermutex);
ffmpeg_printf(100, "::%d released mutex\n", line);
}
//for buffered io (end)encoding
#if 0
static int32_t container_set_ffmpeg_buf_seek_time(int32_t *time)
@@ -190,6 +203,7 @@ static int32_t container_set_ffmpeg_buf_seek_time(int32_t *time)
return cERR_CONTAINER_FFMPEG_NO_ERROR;
}
#endif
static int32_t container_set_ffmpeg_buf_size(int32_t *size)
{
if (ffmpeg_buf == NULL)
@@ -203,6 +217,7 @@ static int32_t container_set_ffmpeg_buf_size(int32_t *size)
ffmpeg_buf_size = (*size) + FILLBUFDIFF;
}
}
ffmpeg_printf(10, "size=%d, buffer size=%d\n", (*size), ffmpeg_buf_size);
return cERR_CONTAINER_FFMPEG_NO_ERROR;
}
@@ -216,6 +231,7 @@ static int32_t container_get_ffmpeg_buf_size(int32_t *size)
static int32_t container_get_fillbufstatus(int32_t *size)
{
int32_t rwdiff = 0;
if (ffmpeg_buf != NULL && ffmpeg_buf_read != NULL && ffmpeg_buf_write != NULL)
{
if (ffmpeg_buf_read < ffmpeg_buf_write)
@@ -225,10 +241,13 @@ static int32_t container_get_fillbufstatus(int32_t *size)
rwdiff = (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_read;
rwdiff += ffmpeg_buf_write - ffmpeg_buf;
}
*size = rwdiff;
}
return cERR_CONTAINER_FFMPEG_NO_ERROR;
}
#if 0
static int32_t container_stop_buffer()
{
@@ -236,6 +255,7 @@ static int32_t container_stop_buffer()
return 0;
}
#endif
//flag 0: start direct
//flag 1: from thread
static void ffmpeg_filler(Context_t *context, int32_t id, int32_t *inpause, int32_t flag)
@@ -243,11 +263,13 @@ static void ffmpeg_filler(Context_t *context, int32_t id, int32_t *inpause, int3
int32_t len = 0;
int32_t rwdiff = ffmpeg_buf_size;
uint8_t buf[FILLBUFPAKET];
if (ffmpeg_read_org == NULL || ffmpeg_seek_org == NULL)
{
ffmpeg_err("ffmpeg_read_org or ffmpeg_seek_org is NULL\n");
return;
}
while ((flag == 0 && avContextTab[0] != NULL && avContextTab[0]->pb != NULL && rwdiff > FILLBUFDIFF) ||
(flag == 1 && hasfillerThreadStarted[id] == 1 && avContextTab[0] != NULL && avContextTab[0]->pb != NULL && rwdiff > FILLBUFDIFF))
{
@@ -255,11 +277,13 @@ static void ffmpeg_filler(Context_t *context, int32_t id, int32_t *inpause, int3
{
break;
}
if (flag == 0 && ffmpeg_buf_stop == 1)
{
ffmpeg_buf_stop = 0;
break;
}
getfillerMutex(__FILE__, __FUNCTION__, __LINE__);
//do a seek
if (ffmpeg_do_seek != 0)
@@ -270,42 +294,53 @@ static void ffmpeg_filler(Context_t *context, int32_t id, int32_t *inpause, int3
ffmpeg_buf_write = ffmpeg_buf;
ffmpeg_buf_read = ffmpeg_buf;
}
ffmpeg_do_seek = 0;
}
if (ffmpeg_buf_read == ffmpeg_buf_write)
{
ffmpeg_buf_valid_size = 0;
rwdiff = ffmpeg_buf_size;
}
if (ffmpeg_buf_read < ffmpeg_buf_write)
{
rwdiff = (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_write;
rwdiff += ffmpeg_buf_read - ffmpeg_buf;
}
if (ffmpeg_buf_read > ffmpeg_buf_write)
{
rwdiff = ffmpeg_buf_read - ffmpeg_buf_write;
}
int32_t size = FILLBUFPAKET;
if (rwdiff - FILLBUFDIFF < size)
{
size = (rwdiff - FILLBUFDIFF);
}
if (ffmpeg_buf_write + size > ffmpeg_buf + ffmpeg_buf_size)
{
size = (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_write;
}
if (ffmpeg_buf_write == ffmpeg_buf + ffmpeg_buf_size)
{
ffmpeg_buf_write = ffmpeg_buf;
}
releasefillerMutex(__FILE__, __FUNCTION__, __LINE__);
if (size > 0)
{
if (flag == 1 && hasfillerThreadStarted[id] == 2) break;
len = ffmpeg_read_org(avContextTab[0]->pb->opaque, buf, size);
if (flag == 1 && hasfillerThreadStarted[id] == 2) break;
ffmpeg_printf(20, "buffer-status (free buffer=%d)\n", rwdiff - FILLBUFDIFF - len);
getfillerMutex(__FILE__, __FUNCTION__, __LINE__);
if (len > 0)
{
@@ -333,11 +368,13 @@ static void ffmpeg_filler(Context_t *context, int32_t id, int32_t *inpause, int3
{
int32_t buflen = 0;
(*inpause) = 0;
getfillerMutex(__FILE__, __FUNCTION__, __LINE__);
if (ffmpeg_buf_read < ffmpeg_buf_write)
{
buflen = ffmpeg_buf_write - ffmpeg_buf_read;
}
if (ffmpeg_buf_read > ffmpeg_buf_write)
{
buflen = (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_read;
@@ -355,13 +392,17 @@ static void ffmpeg_fillerTHREAD(Context_t *context)
{
int32_t inpause = 0;
int32_t id = hasfillerThreadStartedID;
ffmpeg_printf(10, "Running ID=%d!\n", id);
while (hasfillerThreadStarted[id] == 1)
{
ffmpeg_filler(context, id, &inpause, 1);
usleep(10000);
}
hasfillerThreadStarted[id] = 0;
ffmpeg_printf(10, "terminating ID=%d\n", id);
}
@@ -370,7 +411,9 @@ static int32_t ffmpeg_start_fillerTHREAD(Context_t *context)
int32_t error;
int32_t ret = 0, i = 0;
pthread_attr_t attr;
ffmpeg_printf(10, "\n");
if (context && context->playback && context->playback->isPlaying)
{
ffmpeg_printf(10, "is Playing\n");
@@ -379,6 +422,7 @@ static int32_t ffmpeg_start_fillerTHREAD(Context_t *context)
{
ffmpeg_printf(10, "is NOT Playing\n");
}
//get filler thread ID
//if the thread hangs for long time, we use a new id
for (i = 0; i < 10; i++)
@@ -389,15 +433,18 @@ static int32_t ffmpeg_start_fillerTHREAD(Context_t *context)
break;
}
}
if (hasfillerThreadStarted[hasfillerThreadStartedID] == 0)
{
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
hasfillerThreadStarted[hasfillerThreadStartedID] = 1;
if ((error = pthread_create(&fillerThread, &attr, (void *)&ffmpeg_fillerTHREAD, context)) != 0)
{
hasfillerThreadStarted[hasfillerThreadStartedID] = 0;
ffmpeg_printf(10, "Error creating filler thread, error:%d:%s\n", error, strerror(error));
ret = cERR_CONTAINER_FFMPEG_ERR;
}
else
@@ -408,8 +455,10 @@ static int32_t ffmpeg_start_fillerTHREAD(Context_t *context)
else
{
ffmpeg_printf(10, "All filler thread ID's in use!\n");
ret = cERR_CONTAINER_FFMPEG_ERR;
}
ffmpeg_printf(10, "exiting with value %d\n", ret);
return ret;
}
@@ -418,9 +467,11 @@ static int32_t ffmpeg_read_real(void *opaque __attribute__((unused)), uint8_t *b
{
int32_t len = buf_size;
int32_t rwdiff = 0;
if (buf_size > 0)
{
getfillerMutex(__FILE__, __FUNCTION__, __LINE__);
if (ffmpeg_buf_read < ffmpeg_buf_write)
rwdiff = ffmpeg_buf_write - ffmpeg_buf_read;
if (ffmpeg_buf_read > ffmpeg_buf_write)
@@ -429,18 +480,22 @@ static int32_t ffmpeg_read_real(void *opaque __attribute__((unused)), uint8_t *b
rwdiff += ffmpeg_buf_write - ffmpeg_buf;
}
rwdiff--;
if (len > rwdiff)
{
len = rwdiff;
}
if (ffmpeg_buf_read + len > ffmpeg_buf + ffmpeg_buf_size)
{
len = (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_read;
}
if (len > 0)
{
memcpy(buf, ffmpeg_buf_read, len);
ffmpeg_buf_read += len;
if (ffmpeg_buf_valid_size < FILLBUFDIFF)
{
if (ffmpeg_buf_valid_size + len > FILLBUFDIFF)
@@ -452,6 +507,7 @@ static int32_t ffmpeg_read_real(void *opaque __attribute__((unused)), uint8_t *b
ffmpeg_buf_valid_size += len;
}
}
if (ffmpeg_buf_read == ffmpeg_buf + ffmpeg_buf_size)
{
ffmpeg_buf_read = ffmpeg_buf;
@@ -463,6 +519,7 @@ static int32_t ffmpeg_read_real(void *opaque __attribute__((unused)), uint8_t *b
}
releasefillerMutex(__FILE__, __FUNCTION__, __LINE__);
}
return len;
}
@@ -471,6 +528,7 @@ static int32_t ffmpeg_read(void *opaque, uint8_t *buf, int32_t buf_size)
int32_t sumlen = 0;
int32_t len = 0;
int32_t count = 2000;
while (sumlen < buf_size && (--count) > 0 && 0 == PlaybackDieNow(0))
{
len = ffmpeg_read_real(opaque, buf, buf_size - sumlen);
@@ -481,6 +539,7 @@ static int32_t ffmpeg_read(void *opaque, uint8_t *buf, int32_t buf_size)
usleep(10000);
}
}
if (count == 0)
{
if (sumlen == 0)
@@ -492,6 +551,7 @@ static int32_t ffmpeg_read(void *opaque, uint8_t *buf, int32_t buf_size)
ffmpeg_err("Timeout, not all buffered data availabel (buf_size=%d sumlen=%d)!\n", buf_size, sumlen);
}
}
return sumlen;
}
@@ -500,10 +560,12 @@ static int64_t ffmpeg_seek(void *opaque __attribute__((unused)), int64_t offset,
int64_t diff;
int32_t rwdiff = 0;
whence &= ~AVSEEK_FORCE;
if (whence != SEEK_CUR && whence != SEEK_SET)
{
return AVERROR(EINVAL);
}
if (whence == SEEK_CUR)
{
diff = offset;
@@ -512,20 +574,25 @@ static int64_t ffmpeg_seek(void *opaque __attribute__((unused)), int64_t offset,
{
diff = offset - avContextTab[0]->pb->pos;
}
if (diff == 0)
{
return avContextTab[0]->pb->pos;
}
getfillerMutex(__FILE__, __FUNCTION__, __LINE__);
if (ffmpeg_buf_read < ffmpeg_buf_write)
{
rwdiff = ffmpeg_buf_write - ffmpeg_buf_read;
}
if (ffmpeg_buf_read > ffmpeg_buf_write)
{
rwdiff = (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_read;
rwdiff += ffmpeg_buf_write - ffmpeg_buf;
}
if (diff > 0 && diff < rwdiff)
{
/* can do the seek inside the buffer */
@@ -557,29 +624,35 @@ static int64_t ffmpeg_seek(void *opaque __attribute__((unused)), int64_t offset,
{
releasefillerMutex(__FILE__, __FUNCTION__, __LINE__);
ffmpeg_printf(20, "real-seek diff=%lld\n", diff);
ffmpeg_do_seek_ret = 0;
ffmpeg_do_seek = diff;
while (ffmpeg_do_seek != 0)
{
usleep(100000);
}
ffmpeg_do_seek = 0;
if (ffmpeg_do_seek_ret < 0)
{
ffmpeg_err("seek not ok ret=%d\n", ffmpeg_do_seek_ret);
return ffmpeg_do_seek_ret;
}
//fill buffer
int32_t count = ffmpeg_buf_seek_time * 10;
int32_t size = 0;
container_get_fillbufstatus(&size);
while (size < ffmpeg_buf_size - FILLBUFDIFF && (--count) > 0)
{
usleep(100000);
container_get_fillbufstatus(&size);
}
return avContextTab[0]->pb->pos + diff;
}
releasefillerMutex(__FILE__, __FUNCTION__, __LINE__);
return avContextTab[0]->pb->pos + diff;
}

View File

@@ -56,8 +56,10 @@ static void printContainerCapabilities()
{
int32_t i = 0;
int32_t j = 0;
container_printf(10, "%s::%s\n", __FILE__, __FUNCTION__);
container_printf(10, "Capabilities: ");
for (i = 0; AvailableContainer[i] != NULL; i++)
{
for (j = 0; AvailableContainer[i]->Capabilities[j] != NULL; j++)
@@ -73,7 +75,9 @@ static int32_t selectContainer(Context_t *context, char *extension)
int32_t i = 0;
int32_t j = 0;
int32_t ret = -1;
container_printf(10, "%s::%s\n", __FILE__, __FUNCTION__);
for (i = 0; AvailableContainer[i] != NULL; i++)
{
for (j = 0; AvailableContainer[i]->Capabilities[j] != NULL; j++)
@@ -81,26 +85,32 @@ static int32_t selectContainer(Context_t *context, char *extension)
if (!strcasecmp(AvailableContainer[i]->Capabilities[j], extension))
{
context->container->selectedContainer = AvailableContainer[i];
container_printf(10, "Selected Container: %s\n", context->container->selectedContainer->Name);
ret = 0;
break;
}
}
if (ret == 0)
{
break;
}
}
if (ret != 0)
{
container_err("No Container found :-(\n");
}
return ret;
}
static int Command(Context_t *context, ContainerCmd_t command, void *argument __attribute__((unused)))
{
int ret = 0;
container_printf(10, "%s::%s\n", __FILE__, __FUNCTION__);
switch (command)
@@ -124,9 +134,11 @@ static int Command(Context_t *context, ContainerCmd_t command, void *argument __
container_err("%s::%s ContainerCmd %d not supported!\n", __FILE__, __FUNCTION__, command);
break;
}
return ret;
}
ContainerHandler_t ContainerHandler =
{
"Output",

File diff suppressed because it is too large Load Diff

View File

@@ -5,6 +5,7 @@
#include "flv2mpeg4/flv2mpeg4.h"
typedef struct
{
flv2mpeg4_CTX *ctx;
@@ -15,6 +16,7 @@ typedef struct
Track_t *track;
} Flv2Mpeg4Context;
static int flv2mpeg4_context_write_packet_cb(void *usr_data, int keyframe, int pts, const uint8_t *buf, int size)
{
Flv2Mpeg4Context *ctx = usr_data;
@@ -22,6 +24,7 @@ static int flv2mpeg4_context_write_packet_cb(void *usr_data, int keyframe, int p
{
return -1;
}
AudioVideoOut_t avOut;
avOut.data = (char *)buf;
avOut.len = size;
@@ -34,10 +37,12 @@ static int flv2mpeg4_context_write_packet_cb(void *usr_data, int keyframe, int p
avOut.width = ctx->track->width;
avOut.height = ctx->track->height;
avOut.type = "video";
if (Write(ctx->out_ctx->output->video->Write, ctx->out_ctx, &avOut, avOut.pts) < 0)
{
ffmpeg_err("writing data to video device failed\n");
}
return 0;
}
@@ -48,10 +53,12 @@ static int flv2mpeg4_context_write_extradata_cb(void *usr_data, int width, int h
{
return -1;
}
free(ctx->extradata);
ctx->extradata = malloc(extradatasize);
memcpy(ctx->extradata, extradata, extradatasize);
ctx->extradatasize = extradatasize;
return 0;
}
@@ -59,6 +66,7 @@ static void flv2mpeg4_context_reset(Flv2Mpeg4Context *context)
{
if (context == NULL || context->ctx == NULL)
return;
flv2mpeg4_set_frame(context->ctx, 0, 0);
}
@@ -69,14 +77,19 @@ static int flv2mpeg4_write_packet(Context_t *out_ctx, Flv2Mpeg4Context *mpeg4p2_
mpeg4p2_ctx->ctx = flv2mpeg4_init_ctx(mpeg4p2_ctx, track->width, track->height, flv2mpeg4_context_write_packet_cb, flv2mpeg4_context_write_extradata_cb);
flv2mpeg4_prepare_extra_data(mpeg4p2_ctx->ctx);
}
*pts_current = track->pts = calcPts(cAVIdx, track->stream, pkt->pts);
if ((*pts_current > *pts_latest) && (*pts_current != INVALID_PTS_VALUE))
{
*pts_latest = *pts_current;
}
track->dts = calcPts(cAVIdx, track->stream, pkt->dts);
mpeg4p2_ctx->out_ctx = out_ctx;
mpeg4p2_ctx->track = track;
uint32_t time_ms = (uint32_t)(track->pts / 90);
return flv2mpeg4_process_flv_packet(mpeg4p2_ctx->ctx, 0, pkt->data, pkt->size, time_ms);
}

View File

@@ -14,6 +14,7 @@ typedef struct
AVPacket *second_ip_frame;
} Mpeg4P2Context;
static void set_packet(AVPacket **pkt_dest, AVPacket *pkt_src)
{
if (pkt_dest == NULL)
@@ -82,6 +83,7 @@ static void mpeg4p2_context_reset(Mpeg4P2Context *context)
av_free(context->second_ip_frame);
}
context->second_ip_frame = NULL;
context->b_frames_count = 0;
context->first_ip_frame_written = 0;
context->packet_duration = 0;
@@ -95,6 +97,7 @@ static void mpeg4p2_write(Context_t *ctx, Track_t *track, int avContextIdx, int6
*pts_latest = *pts_current;
}
track->dts = calcPts(avContextIdx, track->stream, pkt->dts);
AudioVideoOut_t avOut;
avOut.data = pkt->data;
avOut.len = pkt->size;
@@ -107,6 +110,7 @@ static void mpeg4p2_write(Context_t *ctx, Track_t *track, int avContextIdx, int6
avOut.width = track->width;
avOut.height = track->height;
avOut.type = "video";
if (Write(ctx->output->video->Write, ctx, &avOut, avOut.pts) < 0)
{
ffmpeg_err("writing data to video device failed\n");
@@ -206,3 +210,4 @@ static int mpeg4p2_write_packet(Context_t *ctx, Mpeg4P2Context *mpeg4p2_ctx, Tra
}
return 0;
}

View File

@@ -121,9 +121,11 @@ int store_avcodec_context(AVCodecContext *avCodecCtx __attribute__((unused)), ui
{
return -1;
}
memset(ptr, 0x00, sizeof(CodecCtxStoreItem_t));
ptr->next = g_codecCtxStoreListHead;
g_codecCtxStoreListHead = ptr;
return 0;
}
#else
@@ -144,6 +146,7 @@ static AVCodecContext *wrapped_avcodec_get_context(uint32_t cAVIdx, AVStream *st
fprintf(stderr, "context3 alloc for stream %d failed\n", (int)stream->id);
return NULL;
}
if (avcodec_parameters_to_context(avCodecCtx, stream->codecpar) < 0)
{
fprintf(stderr, "parameters to context for stream %d failed\n", (int)stream->id);
@@ -151,8 +154,10 @@ static AVCodecContext *wrapped_avcodec_get_context(uint32_t cAVIdx, AVStream *st
return NULL;
}
av_codec_set_pkt_timebase(avCodecCtx, stream->time_base);
store_avcodec_context(avCodecCtx, cAVIdx, stream->id);
}
return avCodecCtx;
#else
return stream->codec;