Changeset 42162


Ignore:
Timestamp:
04/12/18 15:06:43 (6 years ago)
Author:
obi
Message:

update libeplayer3 to v47

Location:
titan/libeplayer3
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • titan/libeplayer3/container/container_ffmpeg.c

    r41899 r42162  
    146146static int32_t seek_target_flag = 0;
    147147
     148static int32_t mutexInitialized = 0;
     149
    148150/* ***************************** */
    149151/* Prototypes                    */
     
    164166    progressive_playback = val;
    165167}
     168
     169static void initMutex(void)
     170{
     171    pthread_mutex_init(&mutex, NULL);
     172    mutexInitialized = 1;
     173}
     174
     175static void getMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int32_t line)
     176{
     177    ffmpeg_printf(100, "::%d requesting mutex\n", line);
     178
     179    if (!mutexInitialized)
     180    {
     181        initMutex();
     182    }
     183
     184    pthread_mutex_lock(&mutex);
     185
     186    ffmpeg_printf(100, "::%d received mutex\n", line);
     187}
     188
     189static void releaseMutex(const char *filename __attribute__((unused)), const const char *function __attribute__((unused)), int32_t line)
     190{
     191    pthread_mutex_unlock(&mutex);
     192
     193    ffmpeg_printf(100, "::%d released mutex\n", line);
     194}
     195
     196typedef int32_t (* Write_FN) (void  *, void *);
     197
     198static int32_t Write(Write_FN WriteFun, void *context, void *privateData, int64_t pts)
     199{
     200    /* Because Write is blocking we will release mutex which protect
     201     * avformat structures, during write time
     202     */
     203    int32_t ret = 0;
     204    releaseMutex(__FILE__, __FUNCTION__,__LINE__);
     205    ret = WriteFun(context, privateData);
     206    getMutex(__FILE__, __FUNCTION__,__LINE__);
     207    return ret;
     208}
     209
    166210
    167211#include "buff_ffmpeg.c"
     
    426470}
    427471
    428 static int32_t mutexInitialized = 0;
     472//static int32_t mutexInitialized = 0;
    429473
    430474void sel_program_id_set(const int32_t val)
     
    496540{
    497541    return av_dict_set(&avio_opts, key, value, flags);
    498 }
    499 
    500 static void initMutex(void)
    501 {
    502     pthread_mutex_init(&mutex, NULL);
    503     mutexInitialized = 1;
    504 }
    505 
    506 static void getMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int32_t line)
    507 {
    508     ffmpeg_printf(100, "::%d requesting mutex\n", line);
    509 
    510     if (!mutexInitialized)
    511     {
    512         initMutex();
    513     }
    514 
    515     pthread_mutex_lock(&mutex);
    516 
    517     ffmpeg_printf(100, "::%d received mutex\n", line);
    518 }
    519 
    520 static void releaseMutex(const char *filename __attribute__((unused)), const const char *function __attribute__((unused)), int32_t line)
    521 {
    522     pthread_mutex_unlock(&mutex);
    523 
    524     ffmpeg_printf(100, "::%d released mutex\n", line);
    525542}
    526543
     
    703720        pts = INVALID_PTS_VALUE;
    704721    }
     722    else
     723    {
     724        pts &= 0x01FFFFFFFF; // PES header can handle only 33 bit PTS
     725    }
    705726
    706727    return pts;
     
    798819    while ( context && context->playback && context->playback->isPlaying )
    799820    {
     821        /* When user press PAUSE we call pause on AUDIO and VIDEO decoders,
     822         * we will not wait here because we can still fill
     823         * DVB drivers buffers at PAUSE time
     824         *
     825         * In the future we can add buffering queue before injection in to
     826         * AUDIO, VIDEO decoders, so we can not wait here
     827         */
     828#ifdef __sh__
    800829        //IF MOVIE IS PAUSED, WAIT
    801830        if (context->playback->isPaused)
     
    806835            continue;
    807836        }
     837#endif
    808838
    809839        if (context->playback->isSeeking)
     
    929959           
    930960            reset_finish_timeout();
    931 
    932             if (context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack) < 0)
    933             {
    934                 ffmpeg_err("error getting video track\n");
     961            if(avContextTab[cAVIdx]->streams[packet.stream_index]->discard != AVDISCARD_ALL)
     962            {
     963                if (context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack) < 0)
     964                {
     965                    ffmpeg_err("error getting video track\n");
     966                }
     967               
     968                if (context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack) < 0)
     969                {
     970                    ffmpeg_err("error getting audio track\n");
     971                }
     972               
     973                if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0)
     974                {
     975                    ffmpeg_err("error getting subtitle track\n");
     976                }
     977            }
     978            else
     979            {
     980                ffmpeg_printf(1, "SKIP DISCARDED PACKET stream_index[%d] pid[%d]\n", packet.size, (int)packet.stream_index, pid);
    935981            }
    936982           
    937             if (context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack) < 0)
    938             {
    939                 ffmpeg_err("error getting audio track\n");
    940             }
    941            
    942             if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0)
    943             {
    944                 ffmpeg_err("error getting subtitle track\n");
    945             }
    946 
    947983            ffmpeg_printf(200, "packet.size %d - index %d\n", packet.size, pid);
    948984
     
    10371073                    }
    10381074
    1039                     if (context->output->video->Write(context, &avOut) < 0)
     1075                    if (Write(context->output->video->Write, context, &avOut, pts) < 0)
    10401076                    {
    10411077                        ffmpeg_err("writing data to video device failed\n");
     
    11131149                    avOut.type       = "audio";
    11141150
    1115                     if (context->output->audio->Write(context, &avOut) < 0)
     1151                    if (Write(context->output->audio->Write, context, &avOut, pts) < 0)
    11161152                    {
    11171153                        ffmpeg_err("(raw pcm) writing data to audio device failed\n");
     
    13081344                        avOut.type       = "audio";
    13091345
    1310                         if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0)
     1346                        if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0)
    13111347                        {
    13121348                            ffmpeg_err("writing data to audio device failed\n");
     
    13311367                    avOut.type       = "audio";
    13321368
    1333                     if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0)
     1369                    if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0)
    13341370                    {
    13351371                        ffmpeg_err("(aac) writing data to audio device failed\n");
     
    13491385                    avOut.type       = "audio";
    13501386
    1351                     if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0)
     1387                    if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0)
    13521388                    {
    13531389                        ffmpeg_err("writing data to audio device failed\n");
     
    13971433                    //obi (end)
    13981434
    1399                     if (context->output->subtitle->Write(context, &subOut) < 0)
     1435                    if (Write(context->output->subtitle->Write, context, &subOut, pts) < 0)
    14001436                    {
    14011437                        ffmpeg_err("writing data to teletext fifo failed\n");
     
    15451581
    15461582#ifdef SAM_CUSTOM_IO
     1583typedef struct CustomIOCtx_t
     1584{
     1585    FILE *pFile;
     1586    FILE *pMoovFile;
     1587    int64_t iOffset;
     1588   
     1589    char *szFile;
     1590    uint64_t iFileSize;
     1591    char *szMoovAtomFile;
     1592    uint64_t iMoovAtomOffset;
     1593} CustomIOCtx_t;
     1594
     1595CustomIOCtx_t* custom_io_tab[IPTV_AV_CONTEXT_MAX_NUM] = {NULL, NULL};
     1596
    15471597int SAM_ReadFunc(void *ptr, uint8_t *buffer, int lSize)
    15481598{
    1549     size_t ret = fread ( (void *) buffer, (size_t) 1, (size_t) lSize, (FILE *)ptr );
    1550     return (int)ret;
     1599    CustomIOCtx_t *io = (CustomIOCtx_t *)ptr;
     1600    int ret = 0;
     1601   
     1602    if (!io->pMoovFile)
     1603    {
     1604        ret = (int)fread( (void *) buffer, (size_t) 1, (size_t) lSize, io->pFile );
     1605    }
     1606    else
     1607    {
     1608        if (io->iOffset < io->iMoovAtomOffset)
     1609        {
     1610            ret = (int)fread( (void *) buffer, (size_t) 1, (size_t) lSize, io->pFile );
     1611            buffer += ret;
     1612            lSize -= ret;
     1613        }
     1614       
     1615        if (io->iOffset + ret >= io->iMoovAtomOffset)
     1616        {
     1617            if (ret)
     1618            {
     1619                if (fseeko(io->pMoovFile, io->iOffset + ret - io->iMoovAtomOffset, SEEK_SET))
     1620                {
     1621                    // something goes wrong
     1622                    ffmpeg_err("fseeko on moov atom file fail \n");
     1623                    lSize = 0;
     1624                }
     1625            }
     1626           
     1627            ret += (int)fread( (void *) buffer, (size_t) 1, (size_t) lSize, io->pMoovFile );
     1628        }
     1629       
     1630        io->iOffset += ret;
     1631    }
     1632    return ret;
    15511633}
    15521634
    15531635// whence: SEEK_SET, SEEK_CUR, SEEK_END (like fseek) and AVSEEK_SIZE
    1554 int64_t SAM_SeekFunc(void* ptr, int64_t pos, int whence)
     1636int64_t SAM_SeekFunc(void *ptr, int64_t pos, int whence)
    15551637{   
    1556     if( AVSEEK_SIZE == whence )
    1557     {
    1558         return -1;
    1559     }
    1560     int ret = fseeko((FILE *)ptr, (off_t)pos, whence);
    1561     if(0 == ret)
    1562     {
    1563         return (off_t)ftello((FILE *)ptr);
     1638    CustomIOCtx_t *io = (CustomIOCtx_t *)ptr;
     1639    int64_t ret = -1;
     1640    if (!io->pMoovFile)
     1641    {
     1642        if( AVSEEK_SIZE != whence )
     1643        {
     1644            ret = (int64_t)fseeko(io->pFile, (off_t)pos, whence);
     1645            if(0 == ret)
     1646            {
     1647                ret = (int64_t)ftello(io->pFile);
     1648            }
     1649        }
     1650    }
     1651    else
     1652    {
     1653        switch(whence)
     1654        {
     1655            case SEEK_SET:
     1656                ret = pos;
     1657                break;
     1658            case SEEK_CUR:
     1659                ret += pos;
     1660                break;
     1661            case SEEK_END:
     1662                ret = io->iFileSize + pos;
     1663                break;
     1664            case AVSEEK_SIZE:
     1665                return io->iFileSize;
     1666            default:
     1667                return -1;
     1668        }
     1669       
     1670        if (ret >= 0 && ret <= io->iFileSize)
     1671        {
     1672            if (ret < io->iMoovAtomOffset)
     1673            {
     1674                if(!fseeko(io->pFile, (off_t)ret, SEEK_SET))
     1675                    io->iOffset = ret;
     1676                else
     1677                    ret = -1;
     1678            }
     1679            else
     1680            {
     1681                if(!fseeko(io->pMoovFile, (off_t)(ret - io->iMoovAtomOffset), SEEK_SET))
     1682                    io->iOffset = ret;
     1683                else
     1684                    ret = -1;
     1685            }
     1686        }
     1687        else
     1688        {
     1689            ret = -1;
     1690        }
    15641691    }
    15651692    return ret;
    15661693}
    15671694
    1568 AVIOContext* container_ffmpeg_get_avio_context(char *filename, size_t avio_ctx_buffer_size)
    1569 {
    1570         if(strstr(filename, "file://") == filename)
    1571         {
    1572             filename += 7;
    1573         }
     1695AVIOContext* container_ffmpeg_get_avio_context(CustomIOCtx_t *custom_io, size_t avio_ctx_buffer_size)
     1696{
     1697    if(strstr(custom_io->szFile, "file://") == custom_io->szFile)
     1698        custom_io->szFile += 7;
     1699   
     1700    custom_io->pFile = fopen(custom_io->szFile, "rb");
     1701    if(NULL == custom_io->pFile)
     1702    {
     1703        return NULL;
     1704    }
     1705   
     1706    if (custom_io->szMoovAtomFile && custom_io->szMoovAtomFile[0] != '\0')
     1707    {
     1708        if(strstr(custom_io->szMoovAtomFile, "file://") == custom_io->szMoovAtomFile)
     1709            custom_io->szMoovAtomFile += 7;
    15741710       
    1575         FILE *pFile = fopen(filename, "rb");
    1576         if(NULL == pFile)
    1577         {
     1711        custom_io->pMoovFile = fopen(custom_io->szMoovAtomFile, "rb");
     1712        if(NULL == custom_io->pMoovFile)
     1713        {
     1714            fclose(custom_io->pFile);
    15781715            return NULL;
    15791716        }
    1580        
    1581         AVIOContext *avio_ctx = NULL;
    1582         uint8_t *avio_ctx_buffer = NULL;
    1583        
    1584         avio_ctx_buffer = av_malloc(avio_ctx_buffer_size);
    1585         if (!avio_ctx_buffer)
    1586         {
    1587             return NULL;
    1588         }
    1589         avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 0, pFile, &SAM_ReadFunc, NULL, &SAM_SeekFunc);
    1590         if (!avio_ctx)
    1591         {
    1592             return NULL;
    1593         }
    1594         return avio_ctx;
     1717    }
     1718   
     1719    AVIOContext *avio_ctx = NULL;
     1720    uint8_t *avio_ctx_buffer = NULL;
     1721   
     1722    avio_ctx_buffer = av_malloc(avio_ctx_buffer_size);
     1723    if (!avio_ctx_buffer)
     1724    {
     1725        return NULL;
     1726    }
     1727    avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 0, custom_io, &SAM_ReadFunc, NULL, &SAM_SeekFunc);
     1728    if (!avio_ctx)
     1729    {
     1730        return NULL;
     1731    }
     1732    return avio_ctx;
    15951733}
    15961734#endif
    15971735
    1598 int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, int32_t AVIdx)
     1736int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uint64_t fileSize, char *moovAtomFile, uint64_t moovAtomOffset, int32_t AVIdx)
    15991737{
    16001738    int32_t err = 0;
     
    16081746       0 == strncmp(filename, "file://", 7))
    16091747    {
    1610         AVIOContext *avio_ctx = container_ffmpeg_get_avio_context(filename, 4096);
     1748        AVIOContext *avio_ctx = NULL;
     1749        custom_io_tab[AVIdx] = malloc(sizeof(CustomIOCtx_t));
     1750        sizeof(custom_io_tab[AVIdx], 0x00, sizeof(CustomIOCtx_t));
     1751       
     1752        custom_io_tab[AVIdx]->szFile = filename;
     1753        custom_io_tab[AVIdx]->iFileSize = fileSize;
     1754        custom_io_tab[AVIdx]->szMoovAtomFile = moovAtomFile;
     1755        custom_io_tab[AVIdx]->iMoovAtomOffset = moovAtomOffset;
     1756       
     1757        avio_ctx = container_ffmpeg_get_avio_context(custom_io_tab[AVIdx], 4096);
    16111758        if(avio_ctx)
    16121759        {
     
    16161763        else
    16171764        {
     1765            free(custom_io_tab[AVIdx]);
     1766            custom_io_tab[AVIdx] = NULL;
    16181767            return cERR_CONTAINER_FFMPEG_OPEN;
    16191768        }
     
    21542303 
    21552304    context->playback->abortRequested = 0;
    2156     int32_t res = container_ffmpeg_init_av_context(context, playFilesNames->szFirstFile, 0);
     2305    int32_t res = container_ffmpeg_init_av_context(context, playFilesNames->szFirstFile, playFilesNames->iFirstFileSize, \
     2306                                                   playFilesNames->szFirstMoovAtomFile, playFilesNames->iFirstMoovAtomOffset, 0);
    21572307    if(0 != res)
    21582308    {
     
    21602310    }
    21612311
    2162     if(playFilesNames->szSecondFile)
    2163     {
    2164         res = container_ffmpeg_init_av_context(context, playFilesNames->szSecondFile, 1);
     2312    if(playFilesNames->szSecondFile && playFilesNames->szSecondFile[0] != '\0')
     2313    {
     2314        res = container_ffmpeg_init_av_context(context, playFilesNames->szSecondFile, playFilesNames->iSecondFileSize, \
     2315                                               playFilesNames->szSecondMoovAtomFile, playFilesNames->iSecondMoovAtomOffset, 1);
    21652316    }
    21662317   
     
    21832334int32_t container_ffmpeg_update_tracks(Context_t *context, char *filename, int32_t initial)
    21842335{
    2185     Track_t *audioTrack = NULL;
    2186     Track_t *subtitleTrack = NULL;
     2336    Track_t *currAudioTrack = NULL;
     2337    Track_t *currSubtitleTrack = NULL;
     2338    uint32_t addedVideoTracksCount = 0;
    21872339   
    21882340    if (terminating)
     
    21912343    }
    21922344   
     2345    getMutex(__FILE__, __FUNCTION__,__LINE__);
     2346   
    21932347    if (initial && context->manager->subtitle)
    21942348    {
    2195         context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack);
     2349        context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &currSubtitleTrack);
    21962350    }
    21972351
    21982352    if (context->manager->audio)
    21992353    {
    2200         context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack);
     2354        context->manager->audio->Command(context, MANAGER_GET_TRACK, &currAudioTrack);
    22012355    }
    22022356
     
    22172371    }
    22182372#endif
    2219 
    22202373
    22212374    ffmpeg_printf(20, "dump format\n");
     
    22952448                }
    22962449               
    2297                 if (!isStreamFromSelProg)
     2450                if (!isStreamFromSelProg) {
     2451                    stream->discard = AVDISCARD_ALL;
     2452                    ffmpeg_printf(1, "cAVIdx[%d]: add DISCARD flag to  stream index[%d]\n", cAVIdx, stream->index);
    22982453                    continue; // skip this stream
     2454                }
    22992455            }
    23002456
     
    23292485            case AVMEDIA_TYPE_VIDEO:
    23302486                ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n", get_codecpar(stream)->codec_type);
    2331 
     2487                stream->discard = AVDISCARD_ALL; /* by default we discard all video streams */
    23322488                if (encoding != NULL)
    23332489                {
     
    24092565                            ffmpeg_err("failed to add track %d\n", n);
    24102566                        }
     2567                        else
     2568                        {
     2569                            if (addedVideoTracksCount == 0) /* at now we can handle only first video track */
     2570                            {
     2571                                stream->discard = AVDISCARD_DEFAULT;
     2572                            }
     2573                            addedVideoTracksCount += 1;
     2574                        }
    24112575                    }
    24122576                }
     
    24182582            case AVMEDIA_TYPE_AUDIO:
    24192583                ffmpeg_printf(10, "CODEC_TYPE_AUDIO %d\n",get_codecpar(stream)->codec_type);
    2420 
     2584                stream->discard = AVDISCARD_ALL;
    24212585                if (encoding != NULL)
    24222586                {
     
    27902954            case AVMEDIA_TYPE_NB:
    27912955            default:
     2956                stream->discard = AVDISCARD_ALL;
    27922957                ffmpeg_err("not handled or unknown codec_type %d\n", get_codecpar(stream)->codec_type);
    27932958             break;
     
    27962961   
    27972962    }
    2798 
     2963   
     2964    if (context->manager->audio)
     2965    {
     2966        Track_t *Tracks = NULL;
     2967        int32_t TrackCount = 0;
     2968        int32_t selTrackIdx = -1;
     2969       
     2970        context->manager->audio->Command(context, MANAGER_REF_LIST, &Tracks);
     2971        context->manager->audio->Command(context, MANAGER_REF_LIST_SIZE, &TrackCount);
     2972        if (Tracks && TrackCount)
     2973        {
     2974            int32_t i;
     2975            for (i=0; i < TrackCount; ++i)
     2976            {
     2977                if (Tracks[i].pending || Tracks[i].Id < 0)
     2978                    continue;
     2979               
     2980                if (selTrackIdx == -1)
     2981                    selTrackIdx = i;
     2982                   
     2983                if (currAudioTrack && currAudioTrack->Id == Tracks[i].Id)
     2984                {
     2985                    selTrackIdx = i;
     2986                    break;
     2987                }
     2988            }
     2989           
     2990            if (selTrackIdx > -1)
     2991            {
     2992                ((AVStream*)Tracks[selTrackIdx].stream)->discard = AVDISCARD_DEFAULT;
     2993                if (!currAudioTrack || currAudioTrack->Id != Tracks[selTrackIdx].Id )
     2994                {
     2995                    context->manager->audio->Command(context, MANAGER_SET, &Tracks[selTrackIdx].Id);
     2996                }
     2997            }
     2998        }
     2999    }
     3000   
     3001    releaseMutex(__FILE__, __FUNCTION__,__LINE__);
    27993002    return cERR_CONTAINER_FFMPEG_NO_ERROR;
    28003003}
     
    31193322    }
    31203323
    3121     getMutex(__FILE__, __FUNCTION__,__LINE__);
     3324//    getMutex(__FILE__, __FUNCTION__,__LINE__);
    31223325
    31233326    if (!context->playback || !context->playback->isPlaying)
     
    31383341        */
    31393342
     3343        getMutex(__FILE__, __FUNCTION__,__LINE__);
    31403344        off_t pos = avio_tell(avContextTab[0]->pb);
     3345        releaseMutex(__FILE__, __FUNCTION__,__LINE__);
    31413346
    31423347        ffmpeg_printf(10, "pos %lld %d\n", pos, avContextTab[0]->bit_rate);
     
    31723377    }
    31733378
    3174     releaseMutex(__FILE__, __FUNCTION__,__LINE__);
     3379//    releaseMutex(__FILE__, __FUNCTION__,__LINE__);
    31753380    return cERR_CONTAINER_FFMPEG_NO_ERROR;
    31763381}
     
    32333438{
    32343439    ffmpeg_printf(10, "track %d\n", *arg);
     3440    getMutex(__FILE__, __FUNCTION__,__LINE__);
     3441    if (context->manager->audio)
     3442    {
     3443        Track_t *Tracks = NULL;
     3444        int32_t TrackCount = 0;
     3445       
     3446        context->manager->audio->Command(context, MANAGER_REF_LIST, &Tracks);
     3447        context->manager->audio->Command(context, MANAGER_REF_LIST_SIZE, &TrackCount);
     3448        if (Tracks && TrackCount)
     3449        {
     3450            int32_t i;
     3451            for (i=0; i < TrackCount; ++i)
     3452            {
     3453                ((AVStream*)Tracks[i].stream)->discard = Tracks[i].Id == *arg ? AVDISCARD_DEFAULT : AVDISCARD_ALL;
     3454            }
     3455        }
     3456    }
     3457    releaseMutex(__FILE__, __FUNCTION__,__LINE__);
    32353458   
    32363459    /* Hellmaster1024: nothing to do here!*/
    3237     int64_t sec = -5;
     3460    int64_t sec = -1;
    32383461    context->playback->Command(context, PLAYBACK_SEEK, (void*)&sec);
    32393462    return cERR_CONTAINER_FFMPEG_NO_ERROR;
     
    32493472     * but now we will not ignore subtitle frame
    32503473     */
    3251     int64_t sec = -5;
     3474    int64_t sec = -1;
    32523475    context->playback->Command(context, PLAYBACK_SEEK, (void*)&sec);
    32533476    //obi
  • titan/libeplayer3/container/flv2mpeg4_ffmpeg.c

    r40322 r42162  
    3939    avOut.type       = "video";
    4040
    41     if (ctx->out_ctx->output->video->Write(ctx->out_ctx, &avOut) < 0)
     41    if (Write(ctx->out_ctx->output->video->Write, ctx->out_ctx, &avOut, avOut.pts) < 0)
    4242    {
    4343        ffmpeg_err("writing data to video device failed\n");
  • titan/libeplayer3/container/mpeg4p2_ffmpeg.c

    r40322 r42162  
    112112    avOut.type       = "video";
    113113
    114     if (ctx->output->video->Write(ctx, &avOut) < 0)
     114    if (Write(ctx->output->video->Write, ctx, &avOut, avOut.pts) < 0)
    115115    {
    116116        ffmpeg_err("writing data to video device failed\n");
  • titan/libeplayer3/include/common.h

    r41347 r42162  
    1010#include <pthread.h>
    1111
    12 typedef char PlayFilesTab_t[2];
     12//typedef char PlayFilesTab_t[2];
    1313
    1414typedef struct PlayFiles_t
     
    1616    char *szFirstFile;
    1717    char *szSecondFile;
     18    char *szFirstMoovAtomFile;
     19    char *szSecondMoovAtomFile;
     20    uint64_t iFirstFileSize;
     21    uint64_t iSecondFileSize;
     22    uint64_t iFirstMoovAtomOffset;
     23    uint64_t iSecondMoovAtomOffset;
    1824} PlayFiles_t;
    1925
  • titan/libeplayer3/include/manager.h

    r41347 r42162  
    1818    MANAGER_UPDATED_TRACK_INFO,
    1919    MANAGER_REGISTER_UPDATED_TRACK_INFO,
     20    MANAGER_REF_LIST,
     21    MANAGER_REF_LIST_SIZE,
    2022} ManagerCmd_t;
    2123
  • titan/libeplayer3/include/output.h

    r40322 r42162  
    2727    OUTPUT_GET_FRAME_COUNT,
    2828    OUTPUT_GET_PROGRESSIVE,
     29    OUTPUT_SET_BUFFER_SIZE,
    2930} OutputCmd_t;
    3031
     
    6869    char * Name;
    6970    int32_t (* Command) (/*Context_t*/void  *, OutputCmd_t, void *);
    70     int32_t (* Write) (/*Context_t*/void  *, void* privateData);
     71    int32_t (* Write) (/*Context_t*/void  *, void *);
    7172    char ** Capabilities;
    7273
  • titan/libeplayer3/include/playback.h

    r40322 r42162  
    33#include <sys/types.h>
    44#include <stdint.h>
     5#include <stdbool.h>
     6
     7typedef void( * PlaybackDieNowCallback )();
     8bool PlaybackDieNowRegisterCallback(PlaybackDieNowCallback callback);
    59
    610typedef enum {PLAYBACK_OPEN, PLAYBACK_CLOSE, PLAYBACK_PLAY, PLAYBACK_STOP, PLAYBACK_PAUSE, PLAYBACK_CONTINUE, PLAYBACK_FLUSH, PLAYBACK_TERM, PLAYBACK_FASTFORWARD, PLAYBACK_SEEK, PLAYBACK_SEEK_ABS, PLAYBACK_PTS, PLAYBACK_LENGTH, PLAYBACK_SWITCH_AUDIO, PLAYBACK_SWITCH_SUBTITLE, PLAYBACK_INFO, PLAYBACK_SLOWMOTION, PLAYBACK_FASTBACKWARD, PLAYBACK_GET_FRAME_COUNT} PlaybackCmd_t;
  • titan/libeplayer3/include/writer.h

    r40322 r42162  
    55#include <stdio.h>
    66#include <stdint.h>
     7#include "common.h"
    78
    89typedef enum { eNone, eAudio, eVideo} eWriterType_t;
     
    2223    unsigned char          Version;
    2324    unsigned int           InfoFlags;
     25    ssize_t                (* WriteV) (int, const struct iovec *, size_t);
    2426} WriterAVCallData_t;
    2527
     
    8789ssize_t write_with_retry(int fd, const void *buf, size_t size);
    8890ssize_t writev_with_retry(int fd, const struct iovec *iov, size_t ic);
     91
     92ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, const void *buf, size_t size);
    8993#endif
  • titan/libeplayer3/main/exteplayer.c

    r41219 r42162  
    8585}
    8686
    87 static int g_pfd[2] = {-1, -1}; /* Used to wake terminate thread */
     87static int g_pfd[2] = {-1, -1}; /* Used to wake terminate thread and kbhit */
    8888static int isPlaybackStarted = 0;
    8989static pthread_mutex_t playbackStartMtx;
     90
     91static void TerminateWakeUp()
     92{
     93    write(g_pfd[1], "x", 1);
     94}
    9095
    9196static void *TermThreadFun(void *arg)
     
    136141    if (FD_ISSET(fd, &readfds))
    137142    {
    138         /*
    139         if ( (cl = accept(fd, NULL, NULL)) == -1)
    140         {
    141             perror("TermThreadFun accept error");
    142             goto finish;
    143         }
    144         */
    145        
    146143        pthread_mutex_lock(&playbackStartMtx);
    147144        PlaybackDieNow(1);
     
    184181{
    185182    struct timeval tv;
    186     fd_set read_fd;
    187 
    188     tv.tv_sec=1;
    189     tv.tv_usec=0;
    190 
    191     FD_ZERO(&read_fd);
    192     FD_SET(0,&read_fd);
    193 
    194     if(-1 == select(1, &read_fd, NULL, NULL, &tv))
     183    fd_set readfds;
     184
     185    tv.tv_sec = 1;
     186    tv.tv_usec = 0;
     187
     188    FD_ZERO(&readfds);
     189    FD_SET(0,&readfds);
     190    FD_SET(g_pfd[0], &readfds);
     191
     192    if(-1 == select(g_pfd[0] + 1, &readfds, NULL, NULL, &tv))
    195193    {
    196194        return 0;
    197195    }
    198196
    199     if(FD_ISSET(0,&read_fd))
     197    if(FD_ISSET(0, &readfds))
    200198    {
    201199        return 1;
     
    369367}
    370368
    371 static int ParseParams(int argc,char* argv[], char *file, char *audioFile, int *pAudioTrackIdx, int *subtitleTrackIdx)
     369static int ParseParams(int argc,char* argv[], PlayFiles_t *playbackFiles, int *pAudioTrackIdx, int *subtitleTrackIdx, uint32_t *linuxDvbBufferSizeMB)
    372370{   
    373371    int ret = 0;
     
    376374    int aopt = 0, bopt = 0;
    377375    char *copt = 0, *dopt = 0;
    378     while ( (c = getopt(argc, argv, "we3dlsrimva:n:x:u:c:h:o:p:P:t:9:0:1:4:f:")) != -1)
     376    while ( (c = getopt(argc, argv, "we3dlsrimva:n:x:u:c:h:o:p:P:t:9:0:1:4:f:b:F:S:O:")) != -1)
    379377    {
    380378        switch (c)
     
    437435            break;
    438436        case 'x':
    439             strncpy(audioFile, optarg, IPTV_MAX_FILE_PATH-1);
    440             map_inter_file_path(audioFile);
     437            if (optarg[0] != '\0')
     438            {
     439                playbackFiles->szSecondFile = malloc(IPTV_MAX_FILE_PATH);
     440                playbackFiles->szSecondFile[0] = '\0';
     441                strncpy(playbackFiles->szSecondFile, optarg, IPTV_MAX_FILE_PATH-1);
     442                playbackFiles->szSecondFile[IPTV_MAX_FILE_PATH] = '\0';
     443                map_inter_file_path(playbackFiles->szSecondFile);
     444            }
    441445            break;
    442446        case 'h':
     
    486490            break;
    487491        }
     492        case 'b':
     493            *linuxDvbBufferSizeMB = 1024 * 1024 * atoi(optarg);
     494            break;
     495        case 'S':
     496            playbackFiles->iFirstFileSize = (uint64_t) strtoull(optarg, (char **)NULL, 10);
     497            break;
     498        case 'O':
     499            playbackFiles->iFirstMoovAtomOffset = (uint64_t) strtoull(optarg, (char **)NULL, 10);
     500            break;
     501        case 'F':
     502            if (optarg[0] != '\0')
     503            {
     504                playbackFiles->szFirstMoovAtomFile = malloc(IPTV_MAX_FILE_PATH);
     505                playbackFiles->szFirstMoovAtomFile[0] = '\0';
     506                strncpy(playbackFiles->szFirstMoovAtomFile, optarg, IPTV_MAX_FILE_PATH-1);
     507                playbackFiles->szFirstMoovAtomFile[IPTV_MAX_FILE_PATH] = '\0';
     508                map_inter_file_path(playbackFiles->szFirstMoovAtomFile);
     509            }
     510            break;
    488511        default:
    489512            printf ("?? getopt returned character code 0%o ??\n", c);
     
    495518    {
    496519        ret = 0;
    497        
     520        playbackFiles->szFirstFile = malloc(IPTV_MAX_FILE_PATH);
     521        playbackFiles->szFirstFile[0] = '\0';
    498522        if(NULL == strstr(argv[optind], "://"))
    499523        {
    500             strcpy(file, "file://");
    501         }
    502         strcat(file, argv[optind]);
    503         map_inter_file_path(file);
    504         printf("file: [%s]\n", file);
     524            strcpy(playbackFiles->szFirstFile, "file://");
     525        }
     526        strcat(playbackFiles->szFirstFile, argv[optind]);
     527        playbackFiles->szFirstFile[IPTV_MAX_FILE_PATH] = '\0';
     528        map_inter_file_path(playbackFiles->szFirstFile);
     529        printf("file: [%s]\n", playbackFiles->szFirstFile);
    505530        ++optind;
    506531    }
     
    516541    pthread_t termThread;
    517542    int isTermThreadStarted = 0;
    518     char file[IPTV_MAX_FILE_PATH];
    519     memset(file, '\0', sizeof(file));
    520    
    521     char audioFile[IPTV_MAX_FILE_PATH];
    522     memset(audioFile, '\0', sizeof(audioFile));
    523543   
    524544    int audioTrackIdx = -1;
    525545    int subtitleTrackIdx = -1;
     546   
     547    uint32_t linuxDvbBufferSizeMB = 0;
    526548   
    527549    char argvBuff[256];
     
    529551    int commandRetVal = -1;
    530552    /* inform client that we can handle additional commands */
    531     fprintf(stderr, "{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 36);
    532 
    533     if (0 != ParseParams(argc, argv, file, audioFile, &audioTrackIdx, &subtitleTrackIdx))
     553    fprintf(stderr, "{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 47);
     554
     555    PlayFiles_t playbackFiles;
     556    memset(&playbackFiles, 0x00, sizeof(playbackFiles));
     557    if (0 != ParseParams(argc, argv, &playbackFiles, &audioTrackIdx, &subtitleTrackIdx, &linuxDvbBufferSizeMB))
    534558    {
    535559        printf("Usage: exteplayer3 filePath [-u user-agent] [-c cookies] [-h headers] [-p prio] [-a] [-d] [-w] [-l] [-s] [-i] [-t audioTrackId] [-9 subtitleTrackId] [-x separateAudioUri] plabackUri\n");
     560        printf("[-b size] Linux DVB output buffer size in MB\n");
    536561        printf("[-a 0|1|2|3] AAC software decoding - 1 bit - AAC ADTS, 2 - bit AAC LATM\n");
    537562        printf("[-e] EAC3 software decoding\n");
     
    560585        printf("[-1 idx] audio MPEG-DASH representation index\n");
    561586        printf("[-f ffopt=ffval] any other ffmpeg option\n");
    562        
     587        printf("[-F path to additional file with moov atom data (used for mp4 playback in progressive download mode)\n");
     588        printf("[-O moov atom offset in the original file (used for mp4 playback in progressive download mode)\n");
     589        printf("[-S remote file size (used for mp4 playback in progressive download mode)\n");
    563590        exit(1);
    564591    }
     
    599626            isTermThreadStarted = 1;
    600627    } while(0);
    601 
     628   
    602629    g_player->playback    = &PlaybackHandler;
    603630    g_player->output      = &OutputHandler;
     
    614641    g_player->output->Command(g_player, OUTPUT_ADD, "video");
    615642    g_player->output->Command(g_player, OUTPUT_ADD, "subtitle");
     643   
     644    //Set LINUX DVB additional write buffer size
     645    if (linuxDvbBufferSizeMB)
     646        g_player->output->Command(g_player, OUTPUT_SET_BUFFER_SIZE, &linuxDvbBufferSizeMB);
     647   
    616648
    617649    g_player->manager->video->Command(g_player, MANAGER_REGISTER_UPDATED_TRACK_INFO, UpdateVideoTrack);
    618     if (strncmp(file, "rtmp", 4) && strncmp(file, "ffrtmp", 4))
     650    if (strncmp(playbackFiles.szFirstFile, "rtmp", 4) && strncmp(playbackFiles.szFirstFile, "ffrtmp", 4))
    619651    {
    620652        g_player->playback->noprobe = 1;
    621653    }
    622654
    623     PlayFiles_t playbackFiles = {file, NULL};
    624     if('\0' != audioFile[0])
    625     {
    626         playbackFiles.szSecondFile = audioFile;
    627     }
    628    
    629655    commandRetVal = g_player->playback->Command(g_player, PLAYBACK_OPEN, &playbackFiles);
    630     fprintf(stderr, "{\"PLAYBACK_OPEN\":{\"OutputName\":\"%s\", \"file\":\"%s\", \"sts\":%d}}\n", g_player->output->Name, file, commandRetVal);
     656    fprintf(stderr, "{\"PLAYBACK_OPEN\":{\"OutputName\":\"%s\", \"file\":\"%s\", \"sts\":%d}}\n", g_player->output->Name, playbackFiles.szFirstFile, commandRetVal);
    631657    if(commandRetVal < 0)
    632658    {
     
    650676        if (g_player->playback->isPlaying)
    651677        {
     678            PlaybackDieNowRegisterCallback(TerminateWakeUp);
     679           
    652680            HandleTracks(g_player->manager->video, (PlaybackCmd_t)-1, "vc");
    653681            HandleTracks(g_player->manager->audio, (PlaybackCmd_t)-1, "al");
     
    670698        }
    671699
    672         while(g_player->playback->isPlaying)
     700        while(g_player->playback->isPlaying && 0 == PlaybackDieNow(0))
    673701        {
    674702            /* we made fgets non blocking */
     
    848876                if (0 == commandRetVal)
    849877                {
    850                     fprintf(stderr, "{\"J\":{\"ms\":%lld}}\n", pts / 90, commandRetVal);
     878                    int64_t lastPts = 0;
     879                    commandRetVal = 1;
     880                    if (g_player->container && g_player->container->selectedContainer)
     881                    {
     882                        commandRetVal = g_player->container->selectedContainer->Command(g_player->container, CONTAINER_LAST_PTS, &lastPts);
     883                    }
     884                   
     885                    if (0 == commandRetVal && lastPts != INVALID_PTS_VALUE)
     886                    {
     887                        fprintf(stderr, "{\"J\":{\"ms\":%lld,\"lms\":%lld}}\n", pts / 90, lastPts / 90);
     888                    }
     889                    else
     890                    {
     891                        fprintf(stderr, "{\"J\":{\"ms\":%lld}}\n", pts / 90);
     892                    }
    851893                }
    852894                break;
     
    905947    close(g_pfd[0]);
    906948    close(g_pfd[1]);
    907 
    908     //printOutputCapabilities();
    909 
     949   
    910950    exit(0);
    911951}
  • titan/libeplayer3/output/linuxdvb_mipsel.c

    r40348 r42162  
    2626#include <stdlib.h>
    2727#include <unistd.h>
     28#include <stdbool.h>
    2829#include <fcntl.h>
    2930#include <sys/types.h>
     
    5354#define LINUXDVB_SILENT
    5455
    55 static unsigned short debug_level = 0;
     56static uint16_t debug_level = 0;
    5657
    5758static const char FILENAME[] = __FILE__;
     
    7374#define cERR_LINUXDVB_ERROR        -1
    7475
    75 static const char VIDEODEV[]    = "/dev/dvb/adapter0/video0";
    76 static const char AUDIODEV[]    = "/dev/dvb/adapter0/audio0";
     76static const char VIDEODEV[] = "/dev/dvb/adapter0/video0";
     77static const char AUDIODEV[] = "/dev/dvb/adapter0/audio0";
    7778
    7879static int videofd      = -1;
     
    8990
    9091unsigned long long int sCURRENT_PTS = 0;
     92bool isBufferedOutput = false;
    9193
    9294pthread_mutex_t LinuxDVBmutex;
     
    9597/* Prototypes                    */
    9698/* ***************************** */
     99int32_t LinuxDvbBuffOpen(Context_t *context, char *type, int outfd);
     100int32_t LinuxDvbBuffClose(Context_t *context);
     101int32_t LinuxDvbBuffFlush(Context_t *context);
     102int32_t LinuxDvbBuffResume(Context_t *context);
     103
     104ssize_t BufferingWriteV(int fd, const struct iovec *iov, size_t ic);
     105int32_t WriteSetBufferingSize(const uint32_t bufferSize);
     106
    97107int LinuxDvbStop(Context_t  *context, char * type);
    98108
     
    101111/* ***************************** */
    102112
    103 void getLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) {
    104 
    105     linuxdvb_printf(250, "requesting mutex\n");
    106 
     113void getLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused)))
     114{
    107115    pthread_mutex_lock(&LinuxDVBmutex);
    108 
    109     linuxdvb_printf(250, "received mutex\n");
    110116}
    111117
    112118void releaseLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) {
    113119    pthread_mutex_unlock(&LinuxDVBmutex);
    114 
    115     linuxdvb_printf(250, "released mutex\n");
    116 
    117120}
    118121
    119122static int LinuxDvbMapBypassMode(int bypass)
    120123{
    121     if( 0x30 == bypass && IsDreambox() )
     124    if (0x30 == bypass && IsDreambox())
    122125    {
    123126        return 0x0f;
     
    126129}
    127130
    128 int LinuxDvbOpen(Context_t  *context __attribute__((unused)), char * type) {
    129     unsigned char video = !strcmp("video", type);
    130     unsigned char audio = !strcmp("audio", type);
     131int LinuxDvbOpen(Context_t  *context __attribute__((unused)), char *type)
     132{
     133    uint8_t video = !strcmp("video", type);
     134    uint8_t audio = !strcmp("audio", type);
    131135
    132136    linuxdvb_printf(10, "v%d a%d\n", video, audio);
     
    138142        if (videofd < 0)
    139143        {
    140             linuxdvb_err("failed to open %s - errno %d\n", VIDEODEV, errno);
    141             linuxdvb_err("%s\n", strerror(errno));
     144            linuxdvb_err("failed to open %s - errno %d, %s\n", VIDEODEV, errno, strerror(errno));
     145            linuxdvb_err("%s\n", );
    142146            return cERR_LINUXDVB_ERROR;
    143147        }
     
    145149        if (ioctl( videofd, VIDEO_CLEAR_BUFFER) == -1)
    146150        {
    147             linuxdvb_err("ioctl failed with errno %d\n", errno);
    148             linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno));
     151            linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    149152        }
    150153
    151154        if (ioctl( videofd, VIDEO_SELECT_SOURCE, (void*)VIDEO_SOURCE_MEMORY) == -1)
    152155        {
    153             linuxdvb_err("ioctl failed with errno %d\n", errno);
    154             linuxdvb_err("VIDEO_SELECT_SOURCE: %s\n", strerror(errno));
     156            linuxdvb_err("VIDEO_SELECT_SOURCE: ERROR %d, %s\n", errno, strerror(errno));
    155157        }
    156158       
    157159        if (ioctl(videofd, VIDEO_FREEZE) == -1)
    158160        {
    159             linuxdvb_err("ioctl failed with errno %d\n", errno);
    160             linuxdvb_err("VIDEO_FREEZE: %s\n", strerror(errno));
    161         }
    162 
     161            linuxdvb_err("VIDEO_FREEZE: ERROR %d, %s\n", errno, strerror(errno));
     162        }
     163
     164        if (isBufferedOutput)
     165            LinuxDvbBuffOpen(context, type, videofd);
    163166    }
    164167    if (audio && audiofd < 0)
     
    168171        if (audiofd < 0)
    169172        {
    170             linuxdvb_err("failed to open %s - errno %d\n", AUDIODEV, errno);
    171             linuxdvb_err("%s\n", strerror(errno));
    172            
     173            linuxdvb_err("failed to open %s - errno %d, %s\n", AUDIODEV, errno, strerror(errno));
    173174            return cERR_LINUXDVB_ERROR;
    174175        }
     
    176177        if (ioctl( audiofd, AUDIO_CLEAR_BUFFER) == -1)
    177178        {
    178             linuxdvb_err("ioctl failed with errno %d\n", errno);
    179             linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno));
     179            linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    180180        }
    181181
    182182        if (ioctl( audiofd, AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) == -1)
    183183        {
    184             linuxdvb_err("ioctl failed with errno %d\n", errno);
    185             linuxdvb_err("AUDIO_SELECT_SOURCE: %s\n", strerror(errno));
     184            linuxdvb_err("AUDIO_SELECT_SOURCE: ERROR %d, %s\n", errno, strerror(errno));
    186185        }
    187186       
    188187        if (ioctl( audiofd, AUDIO_PAUSE) == -1)
    189188        {
    190             linuxdvb_err("ioctl failed with errno %d\n", errno);
    191             linuxdvb_err("AUDIO_PAUSE: %s\n", strerror(errno));
     189            linuxdvb_err("AUDIO_PAUSE: ERROR %d, %s\n", errno, strerror(errno));
    192190        }
    193191       
     192        if (isBufferedOutput)
     193            LinuxDvbBuffOpen(context, type, audiofd);
    194194    }
    195195
     
    197197}
    198198
    199 int LinuxDvbClose(Context_t  *context, char * type)
    200 {
    201     unsigned char video = !strcmp("video", type);
    202     unsigned char audio = !strcmp("audio", type);
     199int LinuxDvbClose(Context_t  *context, char *type)
     200{
     201    uint8_t video = !strcmp("video", type);
     202    uint8_t audio = !strcmp("audio", type);
    203203
    204204    linuxdvb_printf(10, "v%d a%d\n", video, audio);
     
    211211
    212212    getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
     213   
     214    if (isBufferedOutput)
     215        LinuxDvbBuffClose(context);
    213216
    214217    if (video && videofd != -1)
     
    223226    }
    224227
    225     releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
     228    releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__);
    226229    return cERR_LINUXDVB_NO_ERROR;
    227230}
    228231
    229 int LinuxDvbPlay(Context_t  *context, char * type) {
    230     int ret = cERR_LINUXDVB_NO_ERROR;
    231     Writer_t* writer;
    232 
    233     unsigned char video = !strcmp("video", type);
    234     unsigned char audio = !strcmp("audio", type);
     232int LinuxDvbPlay(Context_t  *context, char *type) {
     233    int32_t ret = cERR_LINUXDVB_NO_ERROR;
     234    Writer_t *writer;
     235
     236    uint8_t video = !strcmp("video", type);
     237    uint8_t audio = !strcmp("audio", type);
    235238
    236239    linuxdvb_printf(10, "v%d a%d\n", video, audio);
    237240
    238241    if (video && videofd != -1) {
    239         char * Encoding = NULL;
     242        char *Encoding = NULL;
    240243        context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding);
    241244
     
    243246
    244247        writer = getWriter(Encoding);
    245        
    246         // SULGE VU 4K dont like this
    247         /*
    248         if (0 != ioctl(videofd, VIDEO_STOP))
    249         {
    250             linuxdvb_err("ioctl failed with errno %d\n", errno);
    251             linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno));
    252             ret = cERR_LINUXDVB_ERROR;
    253         }
    254         */
    255 
    256248        if (writer == NULL)
    257249        {
     
    264256            if (ioctl( videofd, VIDEO_SET_STREAMTYPE, (void*) writer->caps->dvbStreamType) == -1)
    265257            {
    266                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    267                 linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno));
     258                linuxdvb_err("VIDEO_SET_STREAMTYPE: ERROR %d, %s\n", errno, strerror(errno));
    268259                ret = cERR_LINUXDVB_ERROR;
    269260            }
     
    273264        if (0 != ioctl(videofd, VIDEO_PLAY))
    274265        {
    275             linuxdvb_err("ioctl failed with errno %d\n", errno);
    276             linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno));
     266            linuxdvb_err("VIDEO_PLAY: ERROR %d, %s\n", errno, strerror(errno));
    277267            ret = cERR_LINUXDVB_ERROR;
    278268        }
     
    280270        if (ioctl(videofd, VIDEO_CONTINUE) == -1)
    281271        {
    282             linuxdvb_err("ioctl failed with errno %d\n", errno);
    283             linuxdvb_err("VIDEO_CONTINUE: %s\n", strerror(errno));
     272            linuxdvb_err("VIDEO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno));
    284273        }
    285274       
    286275        if (ioctl( videofd, VIDEO_CLEAR_BUFFER) == -1)
    287276        {
    288             linuxdvb_err("ioctl failed with errno %d\n", errno);
    289             linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno));
     277            linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    290278        }
    291279    }
     
    298286        writer = getWriter(Encoding);
    299287       
    300         // SULGE VU 4K dont like this
    301         /*
    302         if (0 != ioctl(audiofd, AUDIO_STOP))
    303         {
    304             linuxdvb_err("ioctl failed with errno %d\n", errno);
    305             linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno));
    306             ret = cERR_LINUXDVB_ERROR;
    307         }
    308         */
    309 
    310288        if (writer == NULL)
    311289        {
     
    318296            if (ioctl( audiofd, AUDIO_SET_BYPASS_MODE, (void*) LinuxDvbMapBypassMode(writer->caps->dvbStreamType)) < 0)
    319297            {
    320                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    321                 linuxdvb_err("AUDIO_SET_BYPASS_MODE: %s\n", strerror(errno));
     298                linuxdvb_err("AUDIO_SET_BYPASS_MODE: ERROR %d, %s\n", errno, strerror(errno));
    322299                ret = cERR_LINUXDVB_ERROR;
    323300            }
     
    326303        if (ioctl(audiofd, AUDIO_PLAY) < 0)
    327304        {
    328             linuxdvb_err("ioctl failed with errno %d\n", errno);
    329             linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno));
     305            linuxdvb_err("AUDIO_PLAY: ERROR %d, %s\n", errno, strerror(errno));
    330306            ret = cERR_LINUXDVB_ERROR;
    331307        }
     
    333309        if (ioctl(audiofd, AUDIO_CONTINUE) < 0)
    334310        {
    335             linuxdvb_err("ioctl failed with errno %d\n", errno);
    336             linuxdvb_err("AUDIO_CONTINUE: %s\n", strerror(errno));
     311            linuxdvb_err("AUDIO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno));
    337312            ret = cERR_LINUXDVB_ERROR;
    338313        }
     
    358333        if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1)
    359334        {
    360             linuxdvb_err("ioctl failed with errno %d\n", errno);
    361             linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno));
     335            linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    362336        }
    363337       
    364338        if (ioctl(videofd, VIDEO_STOP) == -1)
    365339        {
    366             linuxdvb_err("ioctl failed with errno %d\n", errno);
    367             linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno));
     340            linuxdvb_err("VIDEO_STOP: ERROR %d, %s\n", errno, strerror(errno));
    368341            ret = cERR_LINUXDVB_ERROR;
    369342        }
     
    371344        ioctl(videofd, VIDEO_SLOWMOTION, 0);
    372345        ioctl(videofd, VIDEO_FAST_FORWARD, 0);
    373 
    374346        ioctl(videofd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX);
    375347    }
     
    377349        if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1)
    378350        {
    379             linuxdvb_err("ioctl failed with errno %d\n", errno);
    380             linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno));
    381         }
    382 
    383         /* set back to normal speed (end trickmodes) */
    384         // if (ioctl(audiofd, AUDIO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1)
    385         // {
    386             // linuxdvb_err("ioctl failed with errno %d\n", errno);
    387             // linuxdvb_err("AUDIO_SET_SPEED: %s\n", strerror(errno));
    388         // }
     351            linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
     352        }
     353
    389354        if (ioctl(audiofd, AUDIO_STOP) == -1)
    390355        {
    391             linuxdvb_err("ioctl failed with errno %d\n", errno);
    392             linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno));
     356            linuxdvb_err("AUDIO_STOP: ERROR %d, %s\n", errno, strerror(errno));
    393357            ret = cERR_LINUXDVB_ERROR;
    394358        }
     
    401365}
    402366
    403 int LinuxDvbPause(Context_t  *context __attribute__((unused)), char * type) {
    404     int ret = cERR_LINUXDVB_NO_ERROR;
    405     unsigned char video = !strcmp("video", type);
    406     unsigned char audio = !strcmp("audio", type);
     367int LinuxDvbPause(Context_t  *context __attribute__((unused)), char *type) {
     368    int32_t ret = cERR_LINUXDVB_NO_ERROR;
     369    uint8_t video = !strcmp("video", type);
     370    uint8_t audio = !strcmp("audio", type);
    407371
    408372    linuxdvb_printf(10, "v%d a%d\n", video, audio);
     
    410374    getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    411375
    412     if (video && videofd != -1) {
     376    if (video && videofd != -1)
     377    {
    413378        if (ioctl(videofd, VIDEO_FREEZE, NULL) == -1)
    414379        {
    415             linuxdvb_err("ioctl failed with errno %d\n", errno);
    416             linuxdvb_err("VIDEO_FREEZE: %s\n", strerror(errno));
    417             ret = cERR_LINUXDVB_ERROR;
    418         }
    419     }
    420     if (audio && audiofd != -1) {
     380            linuxdvb_err("VIDEO_FREEZE: ERROR %d, %s\n", errno, strerror(errno));
     381            ret = cERR_LINUXDVB_ERROR;
     382        }
     383    }
     384   
     385    if (audio && audiofd != -1)
     386    {
    421387        if (ioctl(audiofd, AUDIO_PAUSE, NULL) == -1)
    422388        {
    423             linuxdvb_err("ioctl failed with errno %d\n", errno);
    424             linuxdvb_err("AUDIO_PAUSE: %s\n", strerror(errno));
     389            linuxdvb_err("AUDIO_PAUSE: ERROR %d, %s\n", errno, strerror(errno));
    425390            ret = cERR_LINUXDVB_ERROR;
    426391        }
     
    433398
    434399int LinuxDvbContinue(Context_t  *context __attribute__((unused)), char * type) {
    435     int ret = cERR_LINUXDVB_NO_ERROR;
    436     unsigned char video = !strcmp("video", type);
    437     unsigned char audio = !strcmp("audio", type);
     400    int32_t ret = cERR_LINUXDVB_NO_ERROR;
     401    uint8_t video = !strcmp("video", type);
     402    uint8_t audio = !strcmp("audio", type);
    438403
    439404    linuxdvb_printf(10, "v%d a%d\n", video, audio);
    440405
    441     if (video && videofd != -1) {
     406    if (video && videofd != -1)
     407    {
    442408        if (ioctl(videofd, VIDEO_CONTINUE, NULL) == -1)
    443409        {
    444             linuxdvb_err("ioctl failed with errno %d\n", errno);
    445             linuxdvb_err("VIDEO_CONTINUE: %s\n", strerror(errno));
    446             ret = cERR_LINUXDVB_ERROR;
    447         }
    448     }
    449     if (audio && audiofd != -1) {
     410            linuxdvb_err("VIDEO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno));
     411            ret = cERR_LINUXDVB_ERROR;
     412        }
     413    }
     414   
     415    if (audio && audiofd != -1)
     416    {
    450417        if (ioctl(audiofd, AUDIO_CONTINUE, NULL) == -1)
    451418        {
    452             linuxdvb_err("ioctl failed with errno %d\n", errno);
    453             linuxdvb_err("AUDIO_CONTINUE: %s\n", strerror(errno));
    454             ret = cERR_LINUXDVB_ERROR;
    455         }
    456     }
     419            linuxdvb_err("AUDIO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno));
     420            ret = cERR_LINUXDVB_ERROR;
     421        }
     422    }
     423   
     424    if (isBufferedOutput)
     425        LinuxDvbBuffResume(context);
    457426
    458427    linuxdvb_printf(10, "exiting\n");
    459 
    460 
    461     return ret;
    462 }
    463 
    464 int LinuxDvbReverseDiscontinuity(Context_t  *context __attribute__((unused)), int* surplus) {
    465     int ret = cERR_LINUXDVB_NO_ERROR;
    466     // int dis_type = VIDEO_DISCONTINUITY_CONTINUOUS_REVERSE | *surplus;
    467428   
    468     // linuxdvb_printf(50, "\n");
    469 
    470     // if (ioctl( videofd, VIDEO_DISCONTINUITY, (void*) dis_type) == -1)
    471     // {
    472         // linuxdvb_err("ioctl failed with errno %d\n", errno);
    473         // linuxdvb_err("VIDEO_DISCONTINUITY: %s\n", strerror(errno));
    474     // }
    475 
    476     // linuxdvb_printf(50, "exiting\n");
    477 
    478429    return ret;
    479430}
     
    487438        if(*flag == '1')
    488439        {
    489             //AUDIO_SET_MUTE has no effect with new player
    490             //if (ioctl(audiofd, AUDIO_SET_MUTE, 1) == -1)
    491440            if (ioctl(audiofd, AUDIO_STOP, NULL) == -1)
    492441            {
    493                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    494                 //linuxdvb_err("AUDIO_SET_MUTE: %s\n", strerror(errno));
    495                 linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno));
     442                linuxdvb_err("AUDIO_STOP: ERROR %d, %s\n", errno, strerror(errno));
    496443                ret = cERR_LINUXDVB_ERROR;
    497444            }
     
    499446        else
    500447        {
    501             //AUDIO_SET_MUTE has no effect with new player
    502             //if (ioctl(audiofd, AUDIO_SET_MUTE, 0) == -1)
    503448            if (ioctl(audiofd, AUDIO_PLAY) == -1)
    504449            {
    505                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    506                 //linuxdvb_err("AUDIO_SET_MUTE: %s\n", strerror(errno));
    507                 linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno));
     450                linuxdvb_err("AUDIO_PLAY: ERROR %d, %s\n", errno, strerror(errno));
    508451                ret = cERR_LINUXDVB_ERROR;
    509452            }
     
    516459}
    517460
    518 
    519461int LinuxDvbFlush(Context_t  *context __attribute__((unused)), char * type)
    520462{
    521     // unsigned char video = !strcmp("video", type);
    522     // unsigned char audio = !strcmp("audio", type);
    523 
    524     // linuxdvb_printf(10, "v%d a%d\n", video, audio);
    525 
    526     // if ( (video && videofd != -1) || (audio && audiofd != -1) ) {
    527         // getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    528 
    529         // if (video && videofd != -1) {
    530             // if (ioctl(videofd, VIDEO_FLUSH, NULL) == -1)
    531             // {
    532                 // linuxdvb_err("ioctl failed with errno %d\n", errno);
    533                 // linuxdvb_err("VIDEO_FLUSH: %s\n", strerror(errno));
    534             // }
    535         // }
    536 
    537         // if (audio && audiofd != -1) {
    538             // if (ioctl(audiofd, AUDIO_FLUSH, NULL) == -1)
    539             // {
    540                 // linuxdvb_err("ioctl failed with errno %d\n", errno);
    541                 // linuxdvb_err("AUDIO_FLUSH: %s\n", strerror(errno));
    542             // }
    543         // }
    544 
    545         // releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    546     // }
    547 
    548     // linuxdvb_printf(10, "exiting\n");
    549 
    550463    return cERR_LINUXDVB_NO_ERROR;
    551464}
    552465
    553 #ifndef use_set_speed_instead_ff
    554 int LinuxDvbFastForward(Context_t  *context, char * type) {
    555     int ret = cERR_LINUXDVB_NO_ERROR;
    556 
    557     unsigned char video = !strcmp("video", type);
    558     unsigned char audio = !strcmp("audio", type);
    559 
    560     linuxdvb_printf(10, "v%d a%d speed %d\n", video, audio, context->playback->Speed);
    561 
    562     if (video && videofd != -1) {
    563 
    564         getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    565 
    566         /* konfetti comment: speed is a value given in skipped frames */
    567 
    568         if (ioctl(videofd, VIDEO_FAST_FORWARD, context->playback->Speed) == -1)
    569         {
    570             linuxdvb_err("ioctl failed with errno %d\n", errno);
    571             linuxdvb_err("VIDEO_FAST_FORWARD: %s\n", strerror(errno));
    572             ret = cERR_LINUXDVB_ERROR;
    573         }
    574 
    575         releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    576     }
    577 
    578     linuxdvb_printf(10, "exiting with value %d\n", ret);
    579 
    580     return ret;
    581 }
    582 #else
    583 
    584 static unsigned int SpeedList[] =
    585 {
    586     1000, 1100, 1200, 1300, 1500,
    587     2000, 3000, 4000, 5000, 8000,
    588     12000, 16000,
    589     125, 250, 500, 700, 800, 900
    590 };
    591 
    592 int LinuxDvbFastForward(Context_t  *context, char * type) {
    593     int ret = cERR_LINUXDVB_NO_ERROR;
    594     int speedIndex;
    595     unsigned char video = !strcmp("video", type);
    596     unsigned char audio = !strcmp("audio", type);
    597 
    598     linuxdvb_printf(10, "v%d a%d\n", video, audio);
    599 
    600     if (video && videofd != -1) {
    601 
    602         getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    603 
    604         speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int));
    605 
    606         linuxdvb_printf(1, "speedIndex %d\n", speedIndex);
    607 
    608         // if (ioctl(videofd, VIDEO_SET_SPEED, SpeedList[speedIndex]) == -1)
    609         // {
    610             // linuxdvb_err("ioctl failed with errno %d\n", errno);
    611             // linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno));
    612             // ret = cERR_LINUXDVB_ERROR;
    613         // }
    614 
    615         releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    616     }
    617 
    618     if (audio && audiofd != -1) {
    619 
    620         getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    621 
    622         speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int));
    623 
    624         linuxdvb_printf(1, "speedIndex %d\n", speedIndex);
    625 
    626         // if (ioctl(audiofd, AUDIO_SET_SPEED, SpeedList[speedIndex]) == -1)
    627         // {
    628             // linuxdvb_err("ioctl failed with errno %d\n", errno);
    629             // linuxdvb_err("AUDIO_SET_SPEED: %s\n", strerror(errno));
    630             // ret = cERR_LINUXDVB_ERROR;
    631         // }
    632 
    633         releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    634     }
    635 
    636     linuxdvb_printf(10, "exiting with value %d\n", ret);
    637 
    638     return ret;
    639 }
    640 #endif
    641 
    642 
    643 int LinuxDvbReverse(Context_t  *context __attribute__((unused)), char * type __attribute__((unused))) {
    644     int ret = cERR_LINUXDVB_NO_ERROR;
    645     return ret;
    646 }
    647 
    648466int LinuxDvbSlowMotion(Context_t  *context, char * type) {
    649     int ret = cERR_LINUXDVB_NO_ERROR;
    650 
    651     unsigned char video = !strcmp("video", type);
    652     unsigned char audio = !strcmp("audio", type);
     467    int32_t ret = cERR_LINUXDVB_NO_ERROR;
     468
     469    uint8_t video = !strcmp("video", type);
     470    uint8_t audio = !strcmp("audio", type);
    653471
    654472    linuxdvb_printf(10, "v%d a%d\n", video, audio);
     
    660478            if (ioctl(videofd, VIDEO_SLOWMOTION, context->playback->SlowMotion) == -1)
    661479            {
    662                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    663                 linuxdvb_err("VIDEO_SLOWMOTION: %s\n", strerror(errno));
     480                linuxdvb_err("VIDEO_SLOWMOTION: ERROR %d, %s\n", errno, strerror(errno));
    664481                ret = cERR_LINUXDVB_ERROR;
    665482            }
     
    674491}
    675492
    676 int LinuxDvbAVSync(Context_t  *context, char * type __attribute__((unused))) {
    677     int ret = cERR_LINUXDVB_NO_ERROR;
     493int LinuxDvbAVSync(Context_t  *context, char *type __attribute__((unused))) {
     494    int32_t ret = cERR_LINUXDVB_NO_ERROR;
    678495    /* konfetti: this one is dedicated to audiofd so we
    679496     * are ignoring what is given by type! I think we should
     
    687504        if (ioctl(audiofd, AUDIO_SET_AV_SYNC, 0) == -1) //context->playback->AVSync) == -1)
    688505        {
    689             linuxdvb_err("ioctl failed with errno %d\n", errno);
    690             linuxdvb_err("AUDIO_SET_AV_SYNC: %s\n", strerror(errno));
     506            linuxdvb_err("AUDIO_SET_AV_SYNC: ERROR %d, %s\n", errno, strerror(errno));
    691507            ret = cERR_LINUXDVB_ERROR;
    692508        }
     
    698514}
    699515
    700 int LinuxDvbClear(Context_t  *context __attribute__((unused)), char * type)
     516int LinuxDvbClear(Context_t  *context __attribute__((unused)), char *type)
    701517{
    702518    int32_t ret = cERR_LINUXDVB_NO_ERROR;
     
    704520    uint8_t audio = !strcmp("audio", type);
    705521
    706     linuxdvb_printf(10, ">>>>>>>>>>LinuxDvbClear v%d a%d\n", video, audio);
     522    linuxdvb_printf(10, "LinuxDvbClear v%d a%d\n", video, audio);
    707523
    708524    if ( (video && videofd != -1) || (audio && audiofd != -1) )
     
    714530            if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1)
    715531            {
    716                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    717                 linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno));
     532                linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    718533                ret = cERR_LINUXDVB_ERROR;
    719534            }
     
    723538            if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1)
    724539            {
    725                 linuxdvb_err("ioctl failed with errno %d\n", errno);
    726                 linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno));
     540                linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    727541                ret = cERR_LINUXDVB_ERROR;
    728542            }
     
    738552
    739553int LinuxDvbPts(Context_t  *context __attribute__((unused)), unsigned long long int* pts) {
    740     int ret = cERR_LINUXDVB_ERROR;
     554    int32_t ret = cERR_LINUXDVB_ERROR;
    741555   
    742556    linuxdvb_printf(50, "\n");
    743557
    744     // pts is a non writting requests and can be done in parallel to other requests
    745     //getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    746 
     558    // GET_PTS is immutable call, so it can be done in parallel to other requests
    747559    if (videofd > -1 && !ioctl(videofd, VIDEO_GET_PTS, (void*)&sCURRENT_PTS))
    748560    {
     
    751563    else
    752564    {
    753         linuxdvb_err("VIDEO_GET_PTS: %d (%s)\n", errno, strerror(errno));
     565        linuxdvb_err("VIDEO_GET_PTS: ERROR %d, %s\n", errno, strerror(errno));
    754566    }
    755567
     
    762574        else
    763575        {
    764             linuxdvb_err("AUDIO_GET_PTS: %d (%s)\n", errno, strerror(errno));
     576            linuxdvb_err("AUDIO_GET_PTS: ERROR %d, %s\n", errno, strerror(errno));
    765577        }
    766578    }
     
    772584
    773585    *((unsigned long long int *)pts)=(unsigned long long int)sCURRENT_PTS;
    774 
    775     //releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);
    776 
    777586    return ret;
    778587}
     
    780589int LinuxDvbGetFrameCount(Context_t  *context __attribute__((unused)), unsigned long long int* frameCount)
    781590{
    782     int ret = cERR_LINUXDVB_NO_ERROR;
    783     return ret;
    784 }
    785 
    786 int LinuxDvbSwitch(Context_t  *context, char * type)
    787 {
    788     unsigned char audio = !strcmp("audio", type);
    789     unsigned char video = !strcmp("video", type);
    790     Writer_t* writer;
     591    return cERR_LINUXDVB_NO_ERROR;
     592}
     593
     594int LinuxDvbSwitch(Context_t  *context, char *type)
     595{
     596    uint8_t audio = !strcmp("audio", type);
     597    uint8_t video = !strcmp("video", type);
     598    Writer_t *writer;
    791599
    792600    linuxdvb_printf(10, "v%d a%d\n", video, audio);
     
    806614                if (ioctl(audiofd, AUDIO_STOP ,NULL) == -1)
    807615                {
    808                     linuxdvb_err("ioctl failed with errno %d\n", errno);
    809                     linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno));
    810 
     616                    linuxdvb_err("AUDIO_STOP: ERROR %d, %s\n", errno, strerror(errno));
    811617                }
    812618
    813619                if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1)
    814620                {
    815                     linuxdvb_err("ioctl failed with errno %d\n", errno);
    816                     linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno));
    817 
     621                    linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    818622                }
    819623
     
    821625                {
    822626                    linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding);
    823                     // if (ioctl( audiofd, AUDIO_SET_BYPASS_MODE, (void*) AUDIO_ENCODING_MP3) == -1)
    824                     // {
    825                         // linuxdvb_err("ioctl failed with errno %d\n", errno);
    826                         // linuxdvb_err("AUDIO_SET_BYPASS_MODE: %s\n", strerror(errno));
    827                     // }
    828                 } else
     627                }
     628                else
    829629                {
    830630                    linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding);
    831631                    if (ioctl( audiofd, AUDIO_SET_BYPASS_MODE, (void*) LinuxDvbMapBypassMode(writer->caps->dvbStreamType)) == -1)
    832632                    {
    833                         linuxdvb_err("ioctl failed with errno %d\n", errno);
    834                         linuxdvb_err("AUDIO_SET_BYPASS_MODE: %s\n", strerror(errno));
     633                        linuxdvb_err("AUDIO_SET_BYPASS_MODE: ERROR %d, %s\n", errno, strerror(errno));
    835634                    }
    836635                }
     
    838637                if (ioctl(audiofd, AUDIO_PLAY) == -1)
    839638                {
    840                     linuxdvb_err("ioctl failed with errno %d\n", errno);
    841                     linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno));
     639                    linuxdvb_err("AUDIO_PLAY: ERROR %d, %s\n", errno, strerror(errno));
    842640                }
    843641                free(Encoding);
     
    854652                if (ioctl(videofd, VIDEO_STOP ,NULL) == -1)
    855653                {
    856                     linuxdvb_err("ioctl failed with errno %d\n", errno);
    857                     linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno));
     654                    linuxdvb_err("VIDEO_STOP: ERROR %d, %s\n", errno, strerror(errno));
    858655                }
    859656
    860657                if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1)
    861658                {
    862                     linuxdvb_err("ioctl failed with errno %d\n", errno);
    863                     linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno));
     659                    linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno));
    864660                }
    865661
     
    871667                {
    872668                    linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding);
    873                     // if (ioctl( videofd, VIDEO_SET_STREAMTYPE, (void*) VIDEO_ENCODING_AUTO) == -1)
    874                     // {
    875                         // linuxdvb_err("ioctl failed with errno %d\n", errno);
    876                         // linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno));
    877                     // }
    878                 } else
     669                }
     670                else
    879671                {
    880672                    linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding);
    881673                    if (ioctl( videofd, VIDEO_SET_STREAMTYPE, (void*) writer->caps->dvbStreamType) == -1)
    882674                    {
    883                         linuxdvb_err("ioctl failed with errno %d\n", errno);
    884                         linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno));
     675                        linuxdvb_err("VIDEO_SET_STREAMTYPE: ERROR %d, %s\n", errno, strerror(errno));
    885676                    }
    886677                }
     
    891682                     * return an error here and stop the playback mode
    892683                     */
    893                     linuxdvb_err("ioctl failed with errno %d\n", errno);
    894                     linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno));
     684                    linuxdvb_err("VIDEO_PLAY:ERROR %d, %s\n", errno, strerror(errno));
    895685                }
    896686                free(Encoding);
     
    909699}
    910700
    911 static int Write(void  *_context, void* _out)
     701static int Write(void  *_context, void *_out)
    912702{
    913703    Context_t          *context  = (Context_t  *) _context;
    914704    AudioVideoOut_t    *out      = (AudioVideoOut_t*) _out;
    915     int                ret       = cERR_LINUXDVB_NO_ERROR;
    916     int                res       = 0;
    917     unsigned char      video     = 0;
    918     unsigned char      audio     = 0;
    919     Writer_t*          writer;
     705    int32_t            ret       = cERR_LINUXDVB_NO_ERROR;
     706    int32_t            res       = 0;
     707    uint8_t            video     = 0;
     708    uint8_t            audio     = 0;
     709    Writer_t           *writer   = NULL;
    920710    WriterAVCallData_t call;
    921711
     
    935725    if (video)
    936726    {
    937         char * Encoding = NULL;
     727        char *Encoding = NULL;
    938728        context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding);
    939729
     
    1011801            call.Height       = out->height;
    1012802            call.InfoFlags    = out->infoFlags;
    1013             call.Version      = 0; // is unsingned char
     803            call.Version      = 0;
     804            call.WriteV       = isBufferedOutput ? BufferingWriteV : writev_with_retry;
    1014805
    1015806            if (writer->writeData)
     
    1030821    else if (audio)
    1031822    {
    1032         char * Encoding = NULL;
     823        char *Encoding = NULL;
    1033824        context->manager->audio->Command(context, MANAGER_GETENCODING, &Encoding);
    1034825
     
    1060851            call.FrameScale     = out->timeScale;
    1061852            call.InfoFlags      = out->infoFlags;
    1062             call.Version        = 0; /* -1; unsigned char cannot be negative */
     853            call.Version        = 0;
     854            call.WriteV         = isBufferedOutput ? BufferingWriteV : writev_with_retry;
    1063855
    1064856            if (writer->writeData)
     
    1117909    free(Encoding);
    1118910
     911    if (isBufferedOutput)
     912        LinuxDvbBuffFlush(context);
     913   
    1119914    return ret;
    1120915}
     
    12111006        ret = cERR_LINUXDVB_NO_ERROR;
    12121007        *((int*)argument) = videoInfo.progressive;
     1008        break;
     1009    }
     1010    case OUTPUT_SET_BUFFER_SIZE: {
     1011        ret = cERR_LINUXDVB_ERROR;
     1012        if (!isBufferedOutput)
     1013        {
     1014            uint32_t bufferSize = *((uint32_t*)argument);
     1015            ret = cERR_LINUXDVB_NO_ERROR;
     1016            if (bufferSize > 0)
     1017            {
     1018                WriteSetBufferingSize(bufferSize);
     1019                isBufferedOutput = true;
     1020            }
     1021        }
    12131022        break;
    12141023    }
  • titan/libeplayer3/output/output.c

    r40322 r42162  
    530530        }
    531531        break;
     532    }
    532533    case OUTPUT_GET_PROGRESSIVE:
    533534    {
     
    545546        break;
    546547    }
     548    case OUTPUT_SET_BUFFER_SIZE:
     549    {
     550        if (context && context->playback)
     551        {
     552            if (context->output->video)
     553            {
     554                return context->output->video->Command(context, OUTPUT_SET_BUFFER_SIZE, argument);
     555            }
     556            else if (context->output->audio)
     557            {
     558                return context->output->audio->Command(context, OUTPUT_SET_BUFFER_SIZE, argument);
     559            }
     560        }
     561        else
     562        {
     563            ret = cERR_OUTPUT_INTERNAL_ERROR;
     564        }
     565        break;
    547566    }
    548567    default:
  • titan/libeplayer3/output/writer/mipsel/aac.c

    r40322 r42162  
    182182            return 0;
    183183        }
     184       
     185        // STB can handle only AAC LC profile
     186        if (0 == (call->data[2] & 0xC0))
     187        {
     188            // change profile AAC Main -> AAC LC (Low Complexity)
     189            aac_printf(1, "change profile AAC Main -> AAC LC (Low Complexity) in the ADTS header");
     190            call->data[2] = (call->data[2] & 0x1F) | 0x40;
     191        }
    184192    }
    185193    else // check LOAS header
     
    204212    iov[1].iov_base = call->data;
    205213    iov[1].iov_len = call->len;
    206     return writev_with_retry(call->fd, iov, 2);
     214    return call->WriteV(call->fd, iov, 2);
    207215}
    208216
     
    234242        HasADTSHeader(call->data, call->len) )
    235243    {
     244        //printf("%hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n", call->data[0], call->data[1], call->data[2], call->data[3], call->data[4], call->data[5], call->data[6], call->data[7]);
    236245        return _writeData(_call, 0);
    237246    }
     
    274283    iov[1].iov_len = call->len;
    275284   
    276     return writev_with_retry(call->fd, iov, 2);
     285    return call->WriteV(call->fd, iov, 2);
    277286}
    278287
     
    344353    iov[2].iov_len  = pLATMCtx->len;
    345354   
    346     return writev_with_retry(call->fd, iov, 3);
     355    return call->WriteV(call->fd, iov, 3);
    347356}
    348357
  • titan/libeplayer3/output/writer/mipsel/h264.c

    r40362 r42162  
    5656/* Makros/Constants              */
    5757/* ***************************** */
     58#define H264_SILENT
    5859//#define H264_DEBUG
    5960#ifdef H264_DEBUG
     
    8889static unsigned int            CodecDataLen   = 0;
    8990static int                     avc3 = 0;
     91static int                     sps_pps_in_stream = 0;
    9092/* ***************************** */
    9193/* Prototypes                    */
     
    299301    initialHeader = 1;
    300302    avc3 = 0;
     303    sps_pps_in_stream = 0;
    301304    return 0;
    302305}
     
    344347        (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))))
    345348    {
     349        uint32_t i = 0;
     350        uint8_t InsertPrivData = !sps_pps_in_stream;
    346351        uint32_t PacketLength = 0;
    347352        uint32_t FakeStartCode = (call->Version << 8) | PES_VERSION_FAKE_START_CODE;
    348        
    349353        iov[ic++].iov_base = PesHeader;
    350         initialHeader = 0;
    351         if (initialHeader)
     354       
     355        while (InsertPrivData && i < 36 && (call->len - i) > 5)
     356        {
     357            if ( (call->data[i] == 0x00 && call->data[i+1] == 0x00 && call->data[i+2] == 0x00 && call->data[i+3] == 0x01 && (call->data[i+4] == 0x67 || call->data[i+4] == 0x68)) )
     358            {
     359                InsertPrivData = 0;
     360                sps_pps_in_stream = 1;
     361            }
     362            i += 1;
     363        }
     364       
     365        if (InsertPrivData && call->private_size > 0 /*&& initialHeader*/) // some rtsp streams can update codec data at runtime
    352366        {
    353367            initialHeader = 0;
     
    356370            PacketLength     += call->private_size;
    357371        }
    358 
    359         iov[ic].iov_base = "";
    360         iov[ic++].iov_len = 1;
    361372       
    362373        iov[ic].iov_base  = call->data;
     
    364375        PacketLength     += call->len;
    365376       
    366         /*Hellmaster1024: some packets will only be accepted by the player if we send one byte more than
    367                           data is available. The content of this byte does not matter. It will be ignored
    368                           by the player */
    369 //obi
    370         iov[ic].iov_base = "\0";
    371         iov[ic++].iov_len = 1;
    372 //obi (end)
    373377        iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, FakeStartCode);
    374378       
    375         return writev_with_retry(call->fd, iov, ic);
     379        return call->WriteV(call->fd, iov, ic);
    376380    }
    377381    else if (!call->private_data || call->private_size < 7 || 1 != call->private_data[0])
     
    386390    iov[ic++].iov_base = PesHeader;
    387391   
    388     if (initialHeader)
     392    if (!avc3)
    389393    {
    390394        if (CodecData)
     
    458462        iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, 0);
    459463       
    460         len = writev_with_retry(call->fd, iov, ic);
     464        len = call->WriteV(call->fd, iov, ic);
    461465        PacketLength += iov[0].iov_len;
    462466        if (PacketLength != len)
  • titan/libeplayer3/output/writer/mipsel/h265.c

    r40329 r42162  
    5656/* Makros/Constants              */
    5757/* ***************************** */
     58#define H264_SILENT
    5859//#define H265_DEBUG
    5960#ifdef H265_DEBUG
     
    234235        iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, FakeStartCode);
    235236       
    236         return writev_with_retry(call->fd, iov, ic);
     237        return call->WriteV(call->fd, iov, ic);
    237238    }
    238239
     
    303304        iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, 0);
    304305       
    305         len = writev_with_retry(call->fd, iov, ic);
     306        len = call->WriteV(call->fd, iov, ic);
    306307        PacketLength += iov[0].iov_len;
    307308        if (PacketLength != len)
  • titan/libeplayer3/output/writer/mipsel/lpcm.c

    r40322 r42162  
    257257        iov[1].iov_base = frame;
    258258        iov[1].iov_len  = i_frame_size;
    259         i_ret_size += writev_with_retry(call->fd, iov, 2);
     259        i_ret_size += call->WriteV(call->fd, iov, 2);
    260260    }
    261261   
  • titan/libeplayer3/output/writer/mipsel/mpeg4.c

    r40322 r42162  
    134134    }
    135135
    136     struct iovec iov[2];
     136    struct iovec iov[3];
    137137    int ic = 0;
    138138    iov[ic].iov_base = PesHeader;
     
    148148    iov[ic++].iov_len = call->len;
    149149
    150     int len = writev_with_retry(call->fd, iov, ic);
     150    int len = call->WriteV(call->fd, iov, ic);
    151151
    152152    mpeg4_printf(10, "xvid_Write < len=%d\n", len);
  • titan/libeplayer3/output/writer/mipsel/vp.c

    r40329 r42162  
    9797}
    9898
    99 static int writeData(void* _call, int is_vp6)
     99static int writeData(void *_call, int is_vp6)
    100100{
    101101    WriterAVCallData_t* call = (WriterAVCallData_t*) _call;
     
    145145    iov[1].iov_len = call->len;
    146146   
    147     return writev_with_retry(call->fd, iov, 2);
     147    return call->WriteV(call->fd, iov, 2);
    148148}
    149149
  • titan/libeplayer3/output/writer/mipsel/wmv.c

    r40322 r42162  
    197197    }
    198198   
    199     return writev_with_retry(call->fd, iov, ic);
     199    return call->WriteV(call->fd, iov, ic);
    200200}
    201201
  • titan/libeplayer3/output/writer/mipsel/writer.c

    r40362 r42162  
    2929#include "misc.h"
    3030#include "writer.h"
     31#include "common.h"
    3132
    3233/* ***************************** */
     
    9899/*  Functions                    */
    99100/* ***************************** */
     101static void FlusPipe(int pipefd)
     102{
     103    char tmp;
     104    while(1 == read(pipefd, &tmp, 1));
     105}
     106
     107ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, const void *buf, size_t size)
     108{
     109    fd_set rfds;
     110    fd_set wfds;
     111   
     112    ssize_t ret;
     113    int retval = -1;
     114    int maxFd = pipefd > fd ? pipefd : fd;
     115    struct timeval tv;
     116   
     117    while(size > 0 && 0 == PlaybackDieNow(0) && !context->playback->isSeeking)
     118    {
     119        FD_ZERO(&rfds);
     120        FD_ZERO(&wfds);
     121
     122        FD_SET(pipefd, &rfds);
     123        FD_SET(fd, &wfds);
     124
     125        /* When we PAUSE LINUX DVB outputs buffers then audio/video buffers
     126         * will be filled to full unfortunately, in such case after resume
     127         * select never return with fd set - bug in DVB drivers?
     128         * So, there will be to workarounds:
     129         *   1. write to pipe pipe at resume to exit select immediately
     130         *   2. even if fd is not set exit from select after 0,1s
     131         *      (it seems that second workaround is not needed)
     132         */
     133        //tv.tv_sec = 0;
     134        //tv.tv_usec = 100000; // 100ms
     135       
     136        retval = select(maxFd + 1, &rfds, &wfds, NULL, NULL); //&tv);
     137        if (retval < 0)
     138        {
     139            break;
     140        }
     141       
     142        //if (retval == 0)
     143        //{
     144        //    //printf("RETURN FROM SELECT DUE TO TIMEOUT TIMEOUT\n");
     145        //    continue;
     146        //}
     147       
     148        if(FD_ISSET(pipefd, &rfds))
     149        {
     150            FlusPipe(pipefd);
     151            //printf("RETURN FROM SELECT DUE TO pipefd SET\n");
     152            continue;
     153        }
     154       
     155        if(FD_ISSET(fd, &wfds))
     156        {
     157            ret = write(fd, buf, size);
     158            if (ret < 0)
     159            {
     160                switch(errno)
     161                {
     162                    case EINTR:
     163                    case EAGAIN:
     164                        continue;
     165                    default:
     166                        retval = -3;
     167                        break;
     168                }
     169                if (retval < 0)
     170                {
     171                    break;
     172                }
     173               
     174                return ret;
     175            }
     176            else if (ret == 0)
     177            {
     178                //printf("This should not happen. Select return fd ready to write, but write return 0, errno [%d]\n", errno);
     179                tv.tv_sec = 0;
     180                tv.tv_usec = 10000; // 10ms
     181                retval = select(pipefd + 1, &rfds, NULL, NULL, &tv);
     182                if (retval)
     183                    FlusPipe(pipefd);
     184                continue;
     185            }
     186           
     187            size -= ret;
     188            buf += ret;
     189        }
     190    }
     191    return 0;
     192}
     193
    100194ssize_t write_with_retry(int fd, const void *buf, size_t size)
    101195{
  • titan/libeplayer3/output/writer/sh4/aac.c

    r40322 r42162  
    181181            return 0;
    182182        }
     183       
     184        // STB can handle only AAC LC profile
     185        if (0 == (call->data[2] & 0xC0))
     186        {
     187            // change profile AAC Main -> AAC LC (Low Complexity)
     188            aac_printf(1, "change profile AAC Main -> AAC LC (Low Complexity) in the ADTS header");
     189            call->data[2] = (call->data[2] & 0x1F) | 0x40;
     190        }
    183191    }
    184192    else // check LOAS header
  • titan/libeplayer3/output/writer/sh4/h264.c

    r40348 r42162  
    5353/* Makros/Constants              */
    5454/* ***************************** */
    55 //#define H264_DEBUG
    56 
    5755#ifdef SAM_WITH_DEBUG
    5856#define H264_DEBUG
     
    102100static uint32_t  NalLengthBytes = 1;
    103101static int       avc3 = 0;
     102static int       sps_pps_in_stream = 0;
    104103/* ***************************** */
    105104/* Prototypes                    */
     
    260259        (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))))
    261260    {
     261        uint32_t i = 0;
     262        uint8_t InsertPrivData = !sps_pps_in_stream;
    262263        uint32_t PacketLength = 0;
    263         uint32_t FakeStartCode = /*(call->Version << 8) | */PES_VERSION_FAKE_START_CODE;
    264        
     264        uint32_t FakeStartCode = PES_VERSION_FAKE_START_CODE;
    265265        iov[ic++].iov_base = PesHeader;
    266         initialHeader = 0;
    267         if (initialHeader)
     266       
     267        while (InsertPrivData && i < 36 && (call->len - i) > 5)
     268        {
     269            if ( (call->data[i] == 0x00 && call->data[i+1] == 0x00 && call->data[i+2] == 0x00 && call->data[i+3] == 0x01 && (call->data[i+4] == 0x67 || call->data[i+4] == 0x68)) )
     270            {
     271                InsertPrivData = 0;
     272                sps_pps_in_stream = 1;
     273            }
     274            i += 1;
     275        }
     276       
     277        if (InsertPrivData && call->private_size > 0 /*&& initialHeader*/) // some rtsp streams can update codec data at runtime
    268278        {
    269279            initialHeader = 0;
     
    296306    }
    297307
    298     if (initialHeader)
     308    if (!avc3)
    299309    {
    300310        uint8_t  *private_data = call->private_data;
  • titan/libeplayer3/playback/playback.c

    r40364 r42162  
    5858#define cMaxSpeed_fr   -320 /* fixme: revise */
    5959
     60#define MAX_PLAYBACK_DIE_NOW_CALLBACKS 10
     61
    6062/* ***************************** */
    6163/* Varaibles                     */
     
    6870static int32_t PlaybackTerminate(Context_t  *context);
    6971
     72static int8_t dieNow = 0;
     73static PlaybackDieNowCallback playbackDieNowCallbacks[MAX_PLAYBACK_DIE_NOW_CALLBACKS] = {NULL};
     74
    7075/* ***************************** */
    7176/* MISC Functions                */
     
    7378int8_t PlaybackDieNow(int8_t val)
    7479{
    75     static int8_t dieNow = 0;
    76     if(val)
    77     {
     80    if(val && dieNow == 0)
     81    {
     82        uint32_t i = 0;
    7883        dieNow = 1;
     84        while (i < MAX_PLAYBACK_DIE_NOW_CALLBACKS)
     85        {
     86            if (playbackDieNowCallbacks[i] == NULL)
     87            {
     88                break;
     89            }
     90            playbackDieNowCallbacks[i]();
     91            i += 1;
     92        }
    7993    }
    8094    return dieNow;
     95}
     96
     97bool PlaybackDieNowRegisterCallback(PlaybackDieNowCallback callback)
     98{
     99    bool ret = false;
     100    if (callback)
     101    {
     102        uint32_t i = 0;
     103        while (i < MAX_PLAYBACK_DIE_NOW_CALLBACKS)
     104        {
     105            if (playbackDieNowCallbacks[i] == callback)
     106            {
     107                ret = true;
     108                break;
     109            }
     110           
     111            if (playbackDieNowCallbacks[i] == NULL)
     112            {
     113                playbackDieNowCallbacks[i] = callback;
     114                ret = true;
     115                break;
     116            }
     117            i += 1;
     118        }
     119    }
     120    return ret;
    81121}
    82122
Note: See TracChangeset for help on using the changeset viewer.