Changeset 41219
- Timestamp:
- 11/20/17 17:42:27 (6 years ago)
- Location:
- titan/libeplayer3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/libeplayer3/container/container_ffmpeg.c
r40362 r41219 142 142 static int64_t seek_target_seconds = 0; 143 143 static int8_t do_seek_target_seconds = 0; 144 static int64_t prev_seek_time_sec = -1; 144 145 145 146 static int32_t seek_target_flag = 0; … … 198 199 static int32_t rtmp_proto_impl = 0; // 0 - auto, 1 - native, 2 - librtmp 199 200 201 static int32_t g_sel_program_id = -1; 202 200 203 #ifdef HAVE_FLV2MPEG4_CONVERTER 201 204 static int32_t flv2mpeg4_converter = 1; … … 214 217 215 218 static int32_t mutexInitialized = 0; 219 220 void sel_program_id_set(const int32_t val) 221 { 222 g_sel_program_id = val; 223 } 216 224 217 225 void wma_software_decoder_set(const int32_t val) … … 616 624 ffmpeg_printf(10, "seek_target_seconds[%lld]\n", seek_target_seconds); 617 625 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) 619 627 { 620 628 if(NULL != avContextTab[i]) 621 629 { 630 if (i == 1) 631 { 632 prev_seek_time_sec = seek_target_seconds; 633 } 622 634 if (avContextTab[i]->start_time != AV_NOPTS_VALUE) 623 635 { … … 654 666 if(NULL != avContextTab[i]) 655 667 { 656 wrapped_avcodec_flush_buffers(i); 668 if (i != 1) 669 { 670 wrapped_avcodec_flush_buffers(i); 671 } 657 672 } 658 673 else … … 680 695 { 681 696 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 } 682 703 } 683 704 else … … 1869 1890 if(ostrstr(tmpstr, "debuglevel=99") != NULL) 1870 1891 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; 1872 1895 //obi (end) 1873 1896 // SULGE DEBUG ENABLED 1874 1897 // make ffmpeg silen 1875 1898 //av_log_set_level( AV_LOG_DEBUG ); 1876 av_log_set_callback(ffmpeg_silen_callback);1899 //av_log_set_callback(ffmpeg_silen_callback); 1877 1900 1878 1901 context->playback->abortRequested = 0; … … 1950 1973 } 1951 1974 AVFormatContext *avContext = avContextTab[cAVIdx]; 1975 uint32_t *stream_index = NULL; 1976 uint32_t nb_stream_indexes = 0; 1977 1952 1978 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 } 1953 2017 1954 2018 int32_t n = 0; … … 1958 2022 AVStream *stream = avContext->streams[n]; 1959 2023 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); 1965 2047 1966 2048 if(encoding != NULL && !strncmp(encoding, "A_IPCM", 6) && insert_pcm_as_lpcm) -
titan/libeplayer3/main/exteplayer.c
r40322 r41219 32 32 #include <sys/resource.h> 33 33 #include <sys/mman.h> 34 #include <sys/socket.h> 35 #include <sys/un.h> 36 #include <errno.h> 37 38 #include <pthread.h> 34 39 35 40 #include "common.h" 41 #include "misc.h" 36 42 37 43 #define DUMP_BOOL(x) 0 == x ? "false" : "true" … … 48 54 extern void rtmp_proto_impl_set(const int32_t val); 49 55 extern void flv2mpeg4_converter_set(const int32_t val); 56 extern void sel_program_id_set(const int32_t val); 50 57 51 58 extern void pcm_resampling_set(int32_t val); … … 61 68 static Context_t *g_player = NULL; 62 69 70 static 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 87 static int g_pfd[2] = {-1, -1}; /* Used to wake terminate thread */ 88 static int isPlaybackStarted = 0; 89 static pthread_mutex_t playbackStartMtx; 90 91 static 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 155 finish: 156 close(cl); 157 close(fd); 158 pthread_exit(NULL); 159 160 } 161 63 162 static void map_inter_file_path(char *filename) 64 163 { … … 84 183 static int kbhit(void) 85 184 { 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 { 105 196 return 0; 197 } 198 199 if(FD_ISSET(0,&read_fd)) 200 { 201 return 1; 202 } 203 204 return 0; 106 205 } 107 206 … … 277 376 int aopt = 0, bopt = 0; 278 377 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) 280 379 { 281 380 switch (c) … … 328 427 SetNice(atoi(optarg)); 329 428 break; 429 case 'P': 430 sel_program_id_set(atoi(optarg)); 431 break; 330 432 case 't': 331 433 *pAudioTrackIdx = atoi(optarg); … … 412 514 int main(int argc, char* argv[]) 413 515 { 516 pthread_t termThread; 517 int isTermThreadStarted = 0; 414 518 char file[IPTV_MAX_FILE_PATH]; 415 519 memset(file, '\0', sizeof(file)); … … 425 529 int commandRetVal = -1; 426 530 /* inform client that we can handle additional commands */ 427 fprintf(stderr, "{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 3 4);531 fprintf(stderr, "{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 36); 428 532 429 533 if (0 != ParseParams(argc, argv, file, audioFile, &audioTrackIdx, &subtitleTrackIdx)) … … 446 550 printf("[-o 0|1] set progressive download\n"); 447 551 printf("[-p value] nice value\n"); 552 printf("[-P value] select Program ID from multi-service stream\n"); 448 553 printf("[-t id] audio track ID switched on at start\n"); 449 554 printf("[-9 id] subtitle track ID switched on at start\n"); … … 465 570 exit(1); 466 571 } 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); 467 601 468 602 g_player->playback = &PlaybackHandler; … … 505 639 506 640 { 641 pthread_mutex_lock(&playbackStartMtx); 642 isPlaybackStarted = 1; 643 pthread_mutex_unlock(&playbackStartMtx); 644 507 645 commandRetVal = g_player->output->Command(g_player, OUTPUT_OPEN, NULL); 508 646 fprintf(stderr, "{\"OUTPUT_OPEN\":{\"sts\":%d}}\n", commandRetVal); … … 757 895 free(g_player); 758 896 } 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]); 759 907 760 908 //printOutputCapabilities();
Note: See TracChangeset
for help on using the changeset viewer.