Changeset 41219


Ignore:
Timestamp:
11/20/17 17:42:27 (6 years ago)
Author:
obi
Message:

update libeplayer3 v36

Location:
titan/libeplayer3
Files:
2 edited

Legend:

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

    r40362 r41219  
    142142static int64_t seek_target_seconds = 0;
    143143static int8_t do_seek_target_seconds = 0;
     144static int64_t prev_seek_time_sec = -1;
    144145
    145146static int32_t seek_target_flag = 0;
     
    198199static int32_t rtmp_proto_impl = 0; // 0 - auto, 1 - native, 2 - librtmp
    199200
     201static int32_t g_sel_program_id = -1;
     202
    200203#ifdef HAVE_FLV2MPEG4_CONVERTER
    201204static int32_t flv2mpeg4_converter = 1;
     
    214217
    215218static int32_t mutexInitialized = 0;
     219
     220void sel_program_id_set(const int32_t val)
     221{
     222    g_sel_program_id = val;
     223}
    216224
    217225void wma_software_decoder_set(const int32_t val)
     
    616624                ffmpeg_printf(10, "seek_target_seconds[%lld]\n", seek_target_seconds);
    617625                uint32_t i = 0;
    618                 for(i=0; i<IPTV_AV_CONTEXT_MAX_NUM; i+=1)
     626                for(; i<IPTV_AV_CONTEXT_MAX_NUM; i+=1)
    619627                {
    620628                    if(NULL != avContextTab[i])
    621629                    {
     630                        if (i == 1)
     631                        {
     632                            prev_seek_time_sec = seek_target_seconds;
     633                        }
    622634                        if (avContextTab[i]->start_time != AV_NOPTS_VALUE)
    623635                        {
     
    654666                if(NULL != avContextTab[i])
    655667                {
    656                     wrapped_avcodec_flush_buffers(i);
     668                    if (i != 1)
     669                    {
     670                        wrapped_avcodec_flush_buffers(i);
     671                    }
    657672                }
    658673                else
     
    680695            {
    681696                cAVIdx = currentVideoPts <= currentAudioPts ? 0 : 1;
     697                if (1 == cAVIdx && prev_seek_time_sec >= 0 )
     698                {
     699                    avformat_seek_file(avContextTab[1], -1, (currentVideoPts / 90000) * AV_TIME_BASE - AV_TIME_BASE, (currentVideoPts / 90000) * AV_TIME_BASE, (currentVideoPts / 90000) * AV_TIME_BASE + AV_TIME_BASE, 0);
     700                    prev_seek_time_sec = -1;
     701                    wrapped_avcodec_flush_buffers(1);
     702                }
    682703            }
    683704            else
     
    18691890    if(ostrstr(tmpstr, "debuglevel=99") != NULL)
    18701891        av_log_set_level( AV_LOG_DEBUG );
    1871         free(tmpstr), tmpstr = NULL;
     1892    else
     1893        av_log_set_callback(ffmpeg_silen_callback);
     1894    free(tmpstr), tmpstr = NULL;
    18721895//obi (end)
    18731896    // SULGE DEBUG ENABLED
    18741897    // make ffmpeg silen
    18751898    //av_log_set_level( AV_LOG_DEBUG );
    1876     av_log_set_callback(ffmpeg_silen_callback);
     1899    //av_log_set_callback(ffmpeg_silen_callback);
    18771900 
    18781901    context->playback->abortRequested = 0;
     
    19501973        }
    19511974        AVFormatContext *avContext = avContextTab[cAVIdx];
     1975        uint32_t *stream_index = NULL;
     1976        uint32_t nb_stream_indexes = 0;
     1977       
    19521978        ffmpeg_printf(1, "cAVIdx[%d]: number of streams: %d\n", cAVIdx, avContext->nb_streams);
     1979       
     1980        if (avContext->nb_programs > 0)
     1981        {
     1982            uint32_t n = 0;
     1983            ffmpeg_printf(1, "cAVIdx[%d]: stream with multi programs: num of programs %d\n", cAVIdx, avContext->nb_programs);
     1984            for (n = 0; n < avContext->nb_programs && (0 == nb_stream_indexes || stream_index == NULL); n++)
     1985            {
     1986                AVProgram *p = avContext->programs[n];
     1987                if (p->nb_stream_indexes)
     1988                {
     1989                    if (g_sel_program_id > 0)
     1990                    {
     1991                        if (g_sel_program_id == p->id)
     1992                        {
     1993                            stream_index = p->stream_index;
     1994                            nb_stream_indexes = p->nb_stream_indexes;
     1995                            ffmpeg_printf(1, "cAVIdx[%d]: select PROGRAM ID: %d\n", cAVIdx, (int32_t)p->id);
     1996                            break;
     1997                        }
     1998                    }
     1999                    else
     2000                    {
     2001                        uint32_t m = 0;
     2002                        for (m = 0; m < p->nb_stream_indexes; m++)
     2003                        {
     2004                            AVStream *s = avContext->streams[p->stream_index[m]];
     2005                            if (get_codecpar(s)->codec_type == AVMEDIA_TYPE_VIDEO && get_codecpar(s)->width > 0)
     2006                            {
     2007                                ffmpeg_printf(1, "cAVIdx[%d]: PROGRAM ID: %d, width [%d]\n", cAVIdx, (int32_t)p->id, (int32_t)get_codecpar(s)->width);
     2008                                stream_index = p->stream_index;
     2009                                nb_stream_indexes = p->nb_stream_indexes;
     2010                                break;
     2011                            }
     2012                        }
     2013                    }
     2014                }
     2015            }
     2016        }
    19532017       
    19542018        int32_t n = 0;
     
    19582022            AVStream *stream = avContext->streams[n];
    19592023            int32_t version = 0;
    1960 
    1961             char *encoding = Codec2Encoding((int32_t)get_codecpar(stream)->codec_id, (int32_t)get_codecpar(stream)->codec_type, \
    1962                                             (uint8_t *)get_codecpar(stream)->extradata, \
    1963                                             (int)get_codecpar(stream)->extradata_size, \
    1964                                             (int)get_codecpar(stream)->profile, &version);
     2024            char *encoding = NULL;
     2025           
     2026            if (nb_stream_indexes > 0 && stream_index != NULL)
     2027            {
     2028                uint32_t isStreamFromSelProg = 0;
     2029                uint32_t m = 0;
     2030                for (m = 0; m < nb_stream_indexes; m++)
     2031                {
     2032                    if (n == stream_index[m])
     2033                    {
     2034                        isStreamFromSelProg = 1;
     2035                        break;
     2036                    }
     2037                }
     2038               
     2039                if (!isStreamFromSelProg)
     2040                    continue; // skip this stream
     2041            }
     2042
     2043            encoding = Codec2Encoding((int32_t)get_codecpar(stream)->codec_id, (int32_t)get_codecpar(stream)->codec_type, \
     2044                                      (uint8_t *)get_codecpar(stream)->extradata, \
     2045                                      (int)get_codecpar(stream)->extradata_size, \
     2046                                      (int)get_codecpar(stream)->profile, &version);
    19652047           
    19662048            if(encoding != NULL && !strncmp(encoding, "A_IPCM", 6) && insert_pcm_as_lpcm)
  • titan/libeplayer3/main/exteplayer.c

    r40322 r41219  
    3232#include <sys/resource.h>
    3333#include <sys/mman.h>
     34#include <sys/socket.h>
     35#include <sys/un.h>
     36#include <errno.h>
     37
     38#include <pthread.h>
    3439
    3540#include "common.h"
     41#include "misc.h"
    3642
    3743#define DUMP_BOOL(x) 0 == x ? "false"  : "true"
     
    4854extern void            rtmp_proto_impl_set(const int32_t val);
    4955extern void        flv2mpeg4_converter_set(const int32_t val);
     56extern void        sel_program_id_set(const int32_t val);
    5057
    5158extern void pcm_resampling_set(int32_t val);
     
    6168static Context_t *g_player = NULL;
    6269
     70static void TerminateAllSockets(void)
     71{
     72    int i;
     73    for(i=0; i<1024; ++i)
     74    {
     75        if( 0 == shutdown(i, SHUT_RDWR) )
     76        {
     77            /* yes, I know that this is not good practice and I know what this could cause
     78             * but in this use case it can be accepted.
     79             * We must close socket because without closing it recv will return 0 (after shutdown)
     80             * 0 is not correctly handled by external libraries
     81             */
     82            close(i);
     83        }
     84    }
     85}
     86
     87static int g_pfd[2] = {-1, -1}; /* Used to wake terminate thread */
     88static int isPlaybackStarted = 0;
     89static pthread_mutex_t playbackStartMtx;
     90
     91static void *TermThreadFun(void *arg)
     92{
     93    const char *socket_path = "/tmp/iptvplayer_extplayer_term_fd";
     94    struct sockaddr_un addr;
     95    int fd = -1;
     96    int cl = -1;
     97    int nfds = 1;
     98    fd_set readfds;
     99   
     100    unlink(socket_path);
     101    if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
     102    {
     103        perror("TermThreadFun socket error");
     104        goto finish;
     105    }
     106
     107    memset(&addr, 0, sizeof(addr));
     108    addr.sun_family = AF_UNIX;
     109    strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)-1);
     110
     111    if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1)
     112    {
     113        perror("TermThreadFun bind error");
     114        goto finish;
     115    }
     116
     117    if (listen(fd, 1) == -1)
     118    {
     119        perror("TermThreadFun listen error");
     120        goto finish;
     121    }
     122
     123    FD_ZERO(&readfds);
     124    FD_SET(g_pfd[0], &readfds);
     125    FD_SET(fd, &readfds);
     126   
     127    nfds = fd > g_pfd[0] ? fd + 1 : g_pfd[0] + 1;
     128   
     129    while (select(nfds, &readfds, NULL, NULL, NULL) == -1
     130           && errno == EINTR)
     131    {
     132        /* Restart if interrupted by signal */
     133        continue;
     134    }
     135   
     136    if (FD_ISSET(fd, &readfds))
     137    {
     138        /*
     139        if ( (cl = accept(fd, NULL, NULL)) == -1)
     140        {
     141            perror("TermThreadFun accept error");
     142            goto finish;
     143        }
     144        */
     145       
     146        pthread_mutex_lock(&playbackStartMtx);
     147        PlaybackDieNow(1);
     148        if (isPlaybackStarted)
     149            TerminateAllSockets();
     150        else
     151            kill(getpid(), SIGINT);
     152        pthread_mutex_unlock(&playbackStartMtx);
     153    }
     154
     155finish:
     156    close(cl);
     157    close(fd);
     158    pthread_exit(NULL);
     159   
     160}
     161
    63162static void map_inter_file_path(char *filename)
    64163{
     
    84183static int kbhit(void)
    85184{
    86         struct timeval tv;
    87         fd_set read_fd;
    88 
    89         tv.tv_sec=1;
    90         tv.tv_usec=0;
    91 
    92         FD_ZERO(&read_fd);
    93         FD_SET(0,&read_fd);
    94 
    95         if(-1 == select(1, &read_fd, NULL, NULL, &tv))
    96         {
    97             return 0;
    98         }
    99 
    100         if(FD_ISSET(0,&read_fd))
    101         {
    102             return 1;
    103         }
    104 
     185    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))
     195    {
    105196        return 0;
     197    }
     198
     199    if(FD_ISSET(0,&read_fd))
     200    {
     201        return 1;
     202    }
     203
     204    return 0;
    106205}
    107206
     
    277376    int aopt = 0, bopt = 0;
    278377    char *copt = 0, *dopt = 0;
    279     while ( (c = getopt(argc, argv, "we3dlsrimva:n:x:u:c:h:o:p:t:9:0:1:4:f:")) != -1)
     378    while ( (c = getopt(argc, argv, "we3dlsrimva:n:x:u:c:h:o:p:P:t:9:0:1:4:f:")) != -1)
    280379    {
    281380        switch (c)
     
    328427            SetNice(atoi(optarg));
    329428            break;
     429        case 'P':
     430            sel_program_id_set(atoi(optarg));
     431            break;
    330432        case 't':
    331433            *pAudioTrackIdx = atoi(optarg);
     
    412514int main(int argc, char* argv[])
    413515{
     516    pthread_t termThread;
     517    int isTermThreadStarted = 0;
    414518    char file[IPTV_MAX_FILE_PATH];
    415519    memset(file, '\0', sizeof(file));
     
    425529    int commandRetVal = -1;
    426530    /* inform client that we can handle additional commands */
    427     fprintf(stderr, "{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 34);
     531    fprintf(stderr, "{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 36);
    428532
    429533    if (0 != ParseParams(argc, argv, file, audioFile, &audioTrackIdx, &subtitleTrackIdx))
     
    446550        printf("[-o 0|1] set progressive download\n");
    447551        printf("[-p value] nice value\n");
     552        printf("[-P value] select Program ID from multi-service stream\n");
    448553        printf("[-t id] audio track ID switched on at start\n");
    449554        printf("[-9 id] subtitle track ID switched on at start\n");
     
    465570        exit(1);
    466571    }
     572   
     573    pthread_mutex_init(&playbackStartMtx, NULL);
     574    do
     575    {
     576        int flags = 0;
     577       
     578        if (pipe(g_pfd) == -1)
     579            break;
     580       
     581        /* Make read and write ends of pipe nonblocking */
     582        if ((flags = fcntl(g_pfd[0], F_GETFL)) == -1)
     583            break;
     584       
     585        /* Make read end nonblocking */
     586        flags |= O_NONBLOCK;
     587        if (fcntl(g_pfd[0], F_SETFL, flags) == -1)
     588            break;
     589       
     590        if ((flags = fcntl(g_pfd[1], F_GETFL)) == -1)
     591            break;
     592       
     593        /* Make write end nonblocking */
     594        flags |= O_NONBLOCK;
     595        if (fcntl(g_pfd[1], F_SETFL, flags) == -1)
     596            break;
     597       
     598        if(0 == pthread_create(&termThread, NULL, TermThreadFun, NULL))
     599            isTermThreadStarted = 1;
     600    } while(0);
    467601
    468602    g_player->playback    = &PlaybackHandler;
     
    505639   
    506640    {
     641        pthread_mutex_lock(&playbackStartMtx);
     642        isPlaybackStarted = 1;
     643        pthread_mutex_unlock(&playbackStartMtx);
     644       
    507645        commandRetVal = g_player->output->Command(g_player, OUTPUT_OPEN, NULL);
    508646        fprintf(stderr, "{\"OUTPUT_OPEN\":{\"sts\":%d}}\n", commandRetVal);
     
    757895        free(g_player);
    758896    }
     897   
     898    if (isTermThreadStarted && 1 == write(g_pfd[1], "x", 1))
     899    {
     900        pthread_join(termThread, NULL);
     901    }
     902   
     903    pthread_mutex_destroy(&playbackStartMtx);
     904   
     905    close(g_pfd[0]);
     906    close(g_pfd[1]);
    759907
    760908    //printOutputCapabilities();
Note: See TracChangeset for help on using the changeset viewer.