Changeset 44958
- Timestamp:
- 12/08/20 01:35:11 (2 years ago)
- Location:
- titan/libeplayer3
- Files:
-
- 7 added
- 48 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/libeplayer3/Makefile.am.arm
r40363 r44958 1 1 AUTOMAKE_OPTIONS = subdir-objects 2 AM_CFLAGS = -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE 2 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DHAVE_FLV2MPEG4_CONVERTER 3 #AM_CFLAGS = -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE 3 4 4 5 CXXFLAGS = -Wall … … 6 7 AM_CPPFLAGS = \ 7 8 -Iinclude \ 8 -Iexternal 9 -Iexternal \ 10 -Iexternal/flv2mpeg4 9 11 10 12 lib_LTLIBRARIES = libeplayer3.la … … 20 22 output/writer/common/pes.c \ 21 23 output/writer/common/misc.c \ 24 output/writer/common/writer.c \ 25 output/linuxdvb_buffering.c \ 26 output/graphic_subtitle.c \ 22 27 output/linuxdvb_mipsel.c \ 23 28 output/writer/mipsel/writer.c \ 24 29 output/writer/mipsel/aac.c \ 25 30 output/writer/mipsel/ac3.c \ 31 output/writer/mipsel/bcma.c \ 26 32 output/writer/mipsel/mp3.c \ 27 33 output/writer/mipsel/pcm.c \ … … 29 35 output/writer/mipsel/dts.c \ 30 36 output/writer/mipsel/amr.c \ 31 output/writer/mipsel/wma.c \32 37 output/writer/mipsel/h265.c \ 33 38 output/writer/mipsel/h264.c \ 34 output/writer/mipsel/ h263.c \39 output/writer/mipsel/mjpeg.c \ 35 40 output/writer/mipsel/mpeg2.c \ 36 41 output/writer/mipsel/mpeg4.c \ … … 42 47 external/ffmpeg/src/bitstream.c \ 43 48 external/ffmpeg/src/latmenc.c \ 44 external/ffmpeg/src/mpeg4audio.c 45 49 external/ffmpeg/src/mpeg4audio.c \ 50 external/ffmpeg/src/xiph.c \ 51 external/flv2mpeg4/src/m4vencode.c \ 52 external/flv2mpeg4/src/flvdecoder.c \ 53 external/flv2mpeg4/src/dcprediction.c \ 54 external/flv2mpeg4/src/flv2mpeg4.c \ 55 external/plugins/src/png.c 46 56 47 57 #libeplayer3_la_LIBADD = -lpthread -lavformat -lavcodec -lavutil -lswresample -lz -lass -lm -lpng 48 libeplayer3_la_LIBADD = -lpthread -lavformat -lavcodec -lavutil -lswresample 49 58 libeplayer3_la_LIBADD = -lswscale -ldl -lpthread -lavformat -lavcodec -lavutil -lswresample 50 59 51 60 bin_PROGRAMS = eplayer3 52 61 eplayer3_SOURCES = main/exteplayer.c 53 62 #eplayer3_LDADD = -leplayer3 -lpthread 54 eplayer3_LDADD = -leplayer3 -lpthread -lass -lm -lpng 63 #eplayer3_LDADD = -leplayer3 -lpthread -lass -lm -lpng 64 eplayer3_LDADD = -leplayer3 -lswscale -ldl -lpthread -lavformat -lavcodec -lavutil -lswresample 55 65 eplayer3_DEPENDENCIES = libeplayer3.la 56 66 -
titan/libeplayer3/container/buff_ffmpeg.c
r43796 r44958 102 102 } 103 103 104 //printf("ret[%d] playPts[% lld] currPts[%lld] maxInjectedPts[%lld]\n", ret, playPts, currPts, maxInjectedPts);104 //printf("ret[%d] playPts[%"PRId64"] currPts[%"PRId64"] maxInjectedPts[%"PRId64"]\n", ret, playPts, currPts, maxInjectedPts); 105 105 106 106 /* On some STBs PTS readed from decoder is invalid after seek or at start … … 126 126 int32_t len = 0; 127 127 //obi 128 //if(0 == PlaybackDieNow(0))129 //{128 if(0 == PlaybackDieNow(0)) 129 { 130 130 //obi (end) 131 131 len = ffmpeg_real_read_org(opaque, buf, buf_size); 132 132 //obi 133 //while(len < buf_size && g_context && 0 == PlaybackDieNow(0))134 while(len < buf_size && g_context)133 while(len < buf_size && g_context && 0 == PlaybackDieNow(0)) 134 // while(len < buf_size && g_context) 135 135 //obi (end) 136 136 { … … 159 159 } 160 160 //obi 161 //}161 } 162 162 //obi (end) 163 163 //printf("len [%d] finishTimeout[%d]\n", len, finishTimeout); … … 194 194 } 195 195 196 void releasefillerMutex(const char *filename, const c har *function, int line)196 void releasefillerMutex(const char *filename, const const char *function, int line) 197 197 { 198 198 pthread_mutex_unlock(&fillermutex); … … 278 278 { 279 279 //obi 280 //break;280 break; 281 281 //obi (end) 282 282 } … … 532 532 int32_t len = 0; 533 533 int32_t count = 2000; 534 534 535 //obi 535 //while(sumlen < buf_size && (--count) > 0 && 0 == PlaybackDieNow(0))536 while(sumlen < buf_size && (--count) > 0)536 while(sumlen < buf_size && (--count) > 0 && 0 == PlaybackDieNow(0)) 537 // while(sumlen < buf_size && (--count) > 0) 537 538 //obi (end) 538 539 { … … 602 603 { 603 604 /* can do the seek inside the buffer */ 604 ffmpeg_printf(20, "buffer-seek diff=% lld\n", diff);605 ffmpeg_printf(20, "buffer-seek diff=%"PRId64"\n", diff); 605 606 if(diff > (ffmpeg_buf + ffmpeg_buf_size) - ffmpeg_buf_read) 606 607 { … … 615 616 { 616 617 /* can do the seek inside the buffer */ 617 ffmpeg_printf(20, "buffer-seek diff=% lld\n", diff);618 ffmpeg_printf(20, "buffer-seek diff=%"PRId64"\n", diff); 618 619 int32_t tmpdiff = diff * -1; 619 620 if(tmpdiff > ffmpeg_buf_read - ffmpeg_buf) … … 629 630 { 630 631 releasefillerMutex(__FILE__, __FUNCTION__,__LINE__); 631 ffmpeg_printf(20, "real-seek diff=% lld\n", diff);632 ffmpeg_printf(20, "real-seek diff=%"PRId64"\n", diff); 632 633 633 634 ffmpeg_do_seek_ret = 0; -
titan/libeplayer3/container/container.c
r40322 r44958 24 24 25 25 #include "common.h" 26 27 #ifdef SAM_WITH_DEBUG 28 #define CONTAINER_DEBUG 29 #else 30 #define CONTAINER_SILENT 31 #endif 32 33 #ifdef CONTAINER_DEBUG 34 35 static short debug_level = 0; 36 37 #define container_printf(level, x...) do { \ 38 if (debug_level >= level) printf(x); } while (0) 39 #else 40 #define container_printf(level, x...) 41 #endif 42 43 #ifndef CONTAINER_SILENT 44 #define container_err(x...) do { printf(x); } while (0) 45 #else 46 #define container_err(x...) 47 #endif 26 #include "debug.h" 48 27 49 28 static Container_t * AvailableContainer[] = { -
titan/libeplayer3/container/container_ffmpeg.c
r43807 r44958 26 26 /* Includes */ 27 27 /* ***************************** */ 28 #include "debug.h" 28 29 29 30 #include <stdio.h> … … 57 58 #include "pcm.h" 58 59 #include "ffmpeg_metadata.h" 60 59 61 /* ***************************** */ 60 62 /* Makros/Constants */ 61 63 /* ***************************** */ 62 #if (LIBAVFORMAT_VERSION_MAJOR > 57) 63 #define TS_BYTES_SEEKING 0 64 #else 65 #define TS_BYTES_SEEKING 1 66 #endif 64 67 65 68 66 /* Some STB with old kernels have problem with default … … 71 69 * std library. 72 70 */ 73 #define SAM_CUSTOM_IO 74 //obi 75 #define SAM_WITH_DEBUG 76 //obi (end) 77 #ifdef SAM_WITH_DEBUG 78 #define FFMPEG_DEBUG 79 #else 80 #define FFMPEG_SILENT 81 #endif 82 83 #ifdef FFMPEG_DEBUG 84 85 //obi 86 static short debug_level = 10; 87 //obi (end) 88 89 #define ffmpeg_printf(level, fmt, x...) do { \ 90 if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0) 91 #else 92 #define ffmpeg_printf(level, fmt, x...) 93 #endif 94 95 #ifndef FFMPEG_SILENT 96 #define ffmpeg_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0) 97 #else 98 #define ffmpeg_err(fmt, x...) 99 #endif 71 #define USE_CUSTOM_IO 100 72 101 73 /* Error Constants */ … … 123 95 124 96 static pthread_mutex_t mutex; 97 static pthread_mutex_t seek_mutex; 125 98 126 99 static pthread_t PlayThread; … … 129 102 static AVFormatContext *avContextTab[IPTV_AV_CONTEXT_MAX_NUM] = {NULL, NULL}; 130 103 static int32_t use_custom_io[IPTV_AV_CONTEXT_MAX_NUM] = {0, 0}; 131 static AVDictionary * avio_opts = NULL;104 static AVDictionary *g_avio_opts = NULL; 132 105 133 106 static uint8_t isContainerRunning = 0; … … 137 110 static int32_t restart_audio_resampling = 0; 138 111 139 static off_t seek_target_bytes = 0; 140 static int32_t do_seek_target_bytes = 0; 141 142 static int64_t seek_target_seconds = 0; 143 static int8_t do_seek_target_seconds = 0; 144 static int64_t prev_seek_time_sec = -1; 145 146 static int32_t seek_target_flag = 0; 112 static int64_t g_seek_target_seconds = 0; 113 static bool g_do_seek_target_seconds = false; 114 static void *g_stamp; 147 115 148 116 /* ***************************** */ … … 151 119 static int32_t container_ffmpeg_seek_bytes(off_t pos); 152 120 static int32_t container_ffmpeg_seek(Context_t *context, int64_t sec, uint8_t absolute); 153 static int32_t container_ffmpeg_seek_rel(Context_t *context, off_t pos, int64_t pts, int64_t sec);154 121 static int32_t container_ffmpeg_get_length(Context_t *context, int64_t *length); 155 122 static int64_t calcPts(uint32_t avContextIdx, AVStream *stream, int64_t pts); 123 static int64_t doCalcPts(int64_t start_time, const AVRational time_base, int64_t pts); 124 void LinuxDvbBuffSetStamp(void *stamp); 156 125 157 126 /* Progressive playback means that we play local file … … 164 133 progressive_playback = val; 165 134 } 135 136 static void getMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int32_t line) 137 { 138 ffmpeg_printf(100, "::%d requesting mutex\n", line); 139 static bool mutexInitialized = false; 140 141 if (!mutexInitialized) 142 { 143 pthread_mutex_init(&mutex, NULL); 144 mutexInitialized = true; 145 } 146 147 pthread_mutex_lock(&mutex); 148 149 ffmpeg_printf(100, "::%d received mutex\n", line); 150 } 151 152 static void releaseMutex(const char *filename __attribute__((unused)), const const char *function __attribute__((unused)), int32_t line) 153 { 154 pthread_mutex_unlock(&mutex); 155 156 ffmpeg_printf(100, "::%d released mutex\n", line); 157 } 158 159 static void getSeekMutex() 160 { 161 static bool mutexInitialized = false; 162 /* This is not perfect solution because 163 * there could be race conditions and theoretically pthread_mutex_init 164 * could be called twice, but anyway 165 */ 166 if (!mutexInitialized) 167 { 168 pthread_mutex_init(&seek_mutex, NULL); 169 mutexInitialized = true; 170 } 171 172 pthread_mutex_lock(&seek_mutex); 173 } 174 175 static void releaseSeekMutex() 176 { 177 pthread_mutex_unlock(&seek_mutex); 178 } 179 180 typedef int32_t (* Write_FN) (void *, void *); 181 182 static int32_t Write(Write_FN WriteFun, void *context, void *privateData, int64_t pts) 183 { 184 /* Because Write is blocking we will release mutex which protect 185 * avformat structures, during write time 186 */ 187 int32_t ret = 0; 188 releaseMutex(__FILE__, __FUNCTION__,__LINE__); 189 ret = WriteFun(context, privateData); 190 getMutex(__FILE__, __FUNCTION__,__LINE__); 191 return ret; 192 } 193 166 194 167 195 #include "buff_ffmpeg.c" … … 193 221 static int32_t eac3_software_decode = 0; 194 222 static int32_t dts_software_decode = 0; 223 static int32_t amr_software_decode = 1; 224 static int32_t vorbis_software_decode = 1; 225 static int32_t opus_software_decode = 1; 226 195 227 static int32_t pcm_resampling = 1; 196 228 static int32_t stereo_software_decoder = 0; … … 421 453 //obi (end) 422 454 423 static void ffmpeg_silen_callback(void * avcl, int level, const char *fmt, va_list vl)455 static void ffmpeg_silen_callback(void *avcl, int level, const char *fmt, va_list vl) 424 456 { 425 457 return; 426 458 } 427 459 428 static int32_t mutexInitialized = 0;429 430 460 void sel_program_id_set(const int32_t val) 431 461 { … … 463 493 } 464 494 495 void amr_software_decoder_set(const int32_t val) 496 { 497 amr_software_decode = val; 498 } 499 500 void vorbis_software_decoder_set(const int32_t val) 501 { 502 vorbis_software_decode = val; 503 } 504 505 void opus_software_decoder_set(const int32_t val) 506 { 507 opus_software_decode = val; 508 } 509 465 510 void stereo_software_decoder_set(const int32_t val) 466 511 { … … 495 540 int32_t ffmpeg_av_dict_set(const char *key, const char *value, int32_t flags) 496 541 { 497 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 char *function __attribute__((unused)), int32_t line) 521 { 522 pthread_mutex_unlock(&mutex); 523 524 ffmpeg_printf(100, "::%d released mutex\n", line); 542 return av_dict_set(&g_avio_opts, key, value, flags); 525 543 } 526 544 527 545 static char* Codec2Encoding(int32_t codec_id, int32_t media_type, uint8_t *extradata, int extradata_size, int profile, int32_t *version) 528 546 { 529 ffmpeg_printf(10, "Codec ID: %d (%.8 lx)\n", codec_id, codec_id);547 ffmpeg_printf(10, "Codec ID: %d (%.8x)\n", codec_id, codec_id); 530 548 switch (codec_id) 531 549 { … … 533 551 return "V_MPEG1"; 534 552 case AV_CODEC_ID_MPEG2VIDEO: 535 return "V_MPEG1"; 553 return "V_MPEG2"; 554 case AV_CODEC_ID_MJPEG: 555 return "V_MJPEG"; 536 556 case AV_CODEC_ID_H263: 537 557 case AV_CODEC_ID_H263P: … … 552 572 case AV_CODEC_ID_RV10: 553 573 case AV_CODEC_ID_RV20: 554 return "V_RMV"; 574 return "V_RV20"; 575 case AV_CODEC_ID_RV30: 576 return "V_RV30"; 577 case AV_CODEC_ID_RV40: 578 return "V_RV40"; 579 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 21, 100) 580 case AV_CODEC_ID_AVS2: 581 return "V_AVS2"; 582 #endif 555 583 case AV_CODEC_ID_MPEG4: 556 584 return "V_MPEG4"; … … 561 589 case AV_CODEC_ID_MSMPEG4V2: 562 590 case AV_CODEC_ID_MSMPEG4V3: 563 return "V_ DIVX3";591 return "V_MPEG4"; //"V_DIVX3"; 564 592 case AV_CODEC_ID_WMV1: 565 593 *version = 1; … … 590 618 return (mp3_software_decode) ? "A_IPCM" : "A_MP3"; 591 619 case AV_CODEC_ID_AAC: 592 if (extradata_size >= 2) 593 { 620 if (extradata_size >= 2) { 594 621 MPEG4AudioConfig m4ac; 595 622 int off = avpriv_mpeg4audio_get_config(&m4ac, extradata, extradata_size * 8, 1); 596 623 ffmpeg_printf(1,"aac [%d] off[%d]\n", m4ac.object_type, off); 597 if (off < 0 || 2 != m4ac.object_type) 598 { 624 if (off < 0) { 599 625 return "A_IPCM"; 600 626 } 601 } 602 return (aac_software_decode) ? "A_IPCM" : "A_AAC"; 627 else if (0 == m4ac.chan_config && STB_HISILICON != GetSTBType()) { 628 // according to https://wiki.multimedia.cx/index.php/ADTS 629 // "MPEG-4 Channel Configuration - in the case of 0, the channel configuration is sent via an inband PCE" 630 // we already have AAC_LATM formatter which will include PCE 631 return (aac_latm_software_decode) ? "A_IPCM" : "A_AAC_LATM"; 632 } 633 } 634 return (aac_software_decode) ? "A_IPCM" : "A_AAC"; 603 635 case AV_CODEC_ID_AAC_LATM: 604 636 return (aac_latm_software_decode) ? "A_IPCM" : "A_AAC_LATM"; … … 610 642 return (dts_software_decode) ? "A_IPCM" : "A_DTS"; 611 643 case AV_CODEC_ID_WMAV1: 644 return "A_IPCM"; 612 645 case AV_CODEC_ID_WMAV2: 613 646 return (wma_software_decode) ? "A_IPCM" : "A_WMA"; … … 621 654 return "A_IPCM"; 622 655 case AV_CODEC_ID_RA_288: 623 return "A_IPCM";624 case AV_CODEC_ID_VORBIS:625 656 return "A_IPCM"; 626 657 case AV_CODEC_ID_FLAC: … … 642 673 return pcm_resampling ? "A_IPCM" : "A_PCM"; 643 674 case AV_CODEC_ID_AMR_NB: 644 return "A_IPCM";//return "A_AMR"; 675 case AV_CODEC_ID_AMR_WB: 676 return amr_software_decode ? "A_IPCM" : "A_AMR"; 677 case AV_CODEC_ID_VORBIS: 678 return vorbis_software_decode ? "A_IPCM" : "A_VORBIS"; 679 case AV_CODEC_ID_OPUS : 680 return opus_software_decode ? "A_IPCM" : "A_OPUS"; 645 681 646 682 /* In exteplayer3 embedded text subtitle simple printed … … 656 692 return "S_TEXT/ASS"; /* Hellmaster1024: seems to be ASS instead of SSA */ 657 693 case AV_CODEC_ID_DVD_SUBTITLE: 658 case AV_CODEC_ID_DVB_SUBTITLE:659 case AV_CODEC_ID_XSUB:660 694 case AV_CODEC_ID_MOV_TEXT: 661 case AV_CODEC_ID_HDMV_PGS_SUBTITLE:662 695 case AV_CODEC_ID_DVB_TELETEXT: 663 696 // case CODEC_ID_DVB_TELETEXT: … … 669 702 case AV_CODEC_ID_SUBRIP: 670 703 return "S_TEXT/SUBRIP"; 704 case AV_CODEC_ID_WEBVTT: 705 return "S_TEXT/WEBVTT"; 706 case AV_CODEC_ID_HDMV_PGS_SUBTITLE: 707 return "S_GRAPHIC/PGS"; 708 case AV_CODEC_ID_DVB_SUBTITLE: 709 return "S_GRAPHIC/DVB"; 710 case AV_CODEC_ID_XSUB: 711 return "S_GRAPHIC/XSUB"; 671 712 default: 672 ffmpeg_err("Codec ID %d (%.8 lx) not found\n", codec_id, codec_id);713 ffmpeg_err("Codec ID %d (%.8x) not found\n", codec_id, codec_id); 673 714 // Default to injected-pcm for unhandled audio types. 674 715 if (media_type == AVMEDIA_TYPE_AUDIO) … … 676 717 return "A_IPCM"; 677 718 } 678 ffmpeg_err("Codec ID %d (%.8 lx) not found\n", codec_id, codec_id);719 ffmpeg_err("Codec ID %d (%.8x) not found\n", codec_id, codec_id); 679 720 } 680 721 return NULL; 722 } 723 724 static int64_t doCalcPts(int64_t start_time, const AVRational time_base, int64_t pts) 725 { 726 if (time_base.den > 0) 727 { 728 pts = av_rescale(pts, (int64_t)time_base.num * 90000, time_base.den); 729 } 730 731 if (start_time != AV_NOPTS_VALUE) 732 { 733 pts -= 90000 * start_time / AV_TIME_BASE; 734 } 735 736 if (pts & 0x8000000000000000ull) 737 { 738 pts = INVALID_PTS_VALUE; 739 } 740 else 741 { 742 pts &= 0x01FFFFFFFFull; // PES header can handle only 33 bit PTS 743 } 744 745 return pts; 681 746 } 682 747 … … 688 753 return INVALID_PTS_VALUE; 689 754 } 690 else if (stream->time_base.den > 0) 691 { 692 pts = av_rescale(pts, (int64_t)stream->time_base.num * 90000, stream->time_base.den); 693 } 694 695 if (avContextTab[avContextIdx]->start_time != AV_NOPTS_VALUE) 696 { 697 pts -= 90000 * avContextTab[avContextIdx]->start_time / AV_TIME_BASE; 698 } 699 700 if (pts & 0x8000000000000000ull) 701 { 702 pts = INVALID_PTS_VALUE; 703 } 704 705 return pts; 755 756 return doCalcPts(avContextTab[avContextIdx]->start_time, stream->time_base, pts); 706 757 } 707 758 … … 763 814 int64_t lastAudioDts = -1; 764 815 816 int64_t multiContextLastPts[IPTV_AV_CONTEXT_MAX_NUM] = {INVALID_PTS_VALUE, INVALID_PTS_VALUE}; 817 765 818 int64_t showtime = 0; 766 819 int64_t bofcount = 0; … … 777 830 uint32_t cAVIdx = 0; 778 831 832 // for seek 833 int64_t seek_target_seconds = 0; 834 bool do_seek_target_seconds = false; 835 836 int64_t seek_target_bytes = 0; 837 bool do_seek_target_bytes = false; 838 int64_t prev_seek_time_sec = -1; 839 void *stamp; 840 779 841 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56, 34, 100) 780 Mpeg4P2Context mpeg4p2_context; 781 memset(&mpeg4p2_context, 0, sizeof(Mpeg4P2Context)); 782 AVBitStreamFilterContext *mpeg4p2_bsf_context = av_bitstream_filter_init("mpeg4_unpack_bframes"); 842 #ifdef __sh__ 843 Mpeg4P2Context *mpeg4p2_context = NULL; 844 #else 845 Mpeg4P2Context *mpeg4p2_context = mpeg4p2_context_open(); 846 #endif 783 847 #endif 784 848 #ifdef HAVE_FLV2MPEG4_CONVERTER … … 789 853 while ( context->playback->isCreationPhase ) 790 854 { 791 ffmpeg_ err("Thread waiting for end of init phase...\n");855 ffmpeg_printf(10, "Thread waiting for end of init phase...\n"); 792 856 usleep(1000); 793 857 } 794 858 ffmpeg_printf(10, "Running!\n"); 859 860 uint32_t bufferSize = 0; 861 context->output->Command(context, OUTPUT_GET_BUFFER_SIZE, &bufferSize); 862 ffmpeg_printf(10, "bufferSize [%u]\n", bufferSize); 795 863 796 864 int8_t isWaitingForFinish = 0; 797 865 while ( context && context->playback && context->playback->isPlaying ) 798 866 { 799 //IF MOVIE IS PAUSED, WAIT 800 if (context->playback->isPaused) 867 /* When user press PAUSE we call pause on AUDIO and VIDEO decoders, 868 * we will not wait here because we can still fill 869 * DVB drivers buffers at PAUSE time 870 * 871 */ 872 #ifdef __sh__ 873 /* ST DVB drivers skip data if they are written during pause 874 * so, we must wait here if there is not buffering queue 875 */ 876 if (0 == bufferSize && context->playback->isPaused) 801 877 { 802 878 ffmpeg_printf(20, "paused\n"); … … 805 881 continue; 806 882 } 883 #endif 807 884 808 885 if (context->playback->isSeeking) … … 826 903 } 827 904 905 getSeekMutex(); 906 if (g_do_seek_target_seconds) 907 { 908 do_seek_target_seconds = g_do_seek_target_seconds; 909 seek_target_seconds = g_seek_target_seconds; 910 stamp = g_stamp; 911 g_do_seek_target_seconds = false; 912 } 913 releaseSeekMutex(); 914 828 915 if (do_seek_target_seconds || do_seek_target_bytes) 829 916 { … … 831 918 if (do_seek_target_seconds) 832 919 { 833 ffmpeg_printf(10, "seek_target_seconds[% lld]\n", seek_target_seconds);920 ffmpeg_printf(10, "seek_target_seconds[%"PRId64"]\n", seek_target_seconds); 834 921 uint32_t i = 0; 835 922 for(; i<IPTV_AV_CONTEXT_MAX_NUM; i+=1) 836 923 { 924 multiContextLastPts[i] = INVALID_PTS_VALUE; 837 925 if(NULL != avContextTab[i]) 838 926 { … … 844 932 { 845 933 seek_target_seconds += avContextTab[i]->start_time; 846 printf("SEEK SECONDS [%lld]\n", seek_target_seconds);847 934 } 848 935 //av_seek_frame(avContextTab[i], -1, seek_target_seconds, 0); … … 855 942 } 856 943 reset_finish_timeout(); 944 /* 945 if (bufferSize > 0) 946 { 947 context->output->Command(context, OUTPUT_CLEAR, NULL); 948 } 949 */ 857 950 } 858 951 else … … 860 953 container_ffmpeg_seek_bytes(seek_target_bytes); 861 954 } 862 do_seek_target_seconds = 0;863 do_seek_target_bytes = 0;955 do_seek_target_seconds = false; 956 do_seek_target_bytes = false; 864 957 865 958 restart_audio_resampling = 1; … … 867 960 currentAudioPts = -1; 868 961 latestPts = 0; 869 seek_target_flag = 0;870 962 871 963 // flush streams … … 886 978 } 887 979 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56, 34, 100) 888 mpeg4p2_context_reset(&mpeg4p2_context); 889 if (NULL != mpeg4p2_bsf_context) 890 { 891 av_bitstream_filter_close(mpeg4p2_bsf_context); 892 mpeg4p2_bsf_context = av_bitstream_filter_init("mpeg4_unpack_bframes"); 893 } 980 mpeg4p2_context_reset(mpeg4p2_context); 894 981 #endif 895 982 #ifdef HAVE_FLV2MPEG4_CONVERTER … … 903 990 if(NULL != avContextTab[1]) 904 991 { 905 cAVIdx = currentVideoPts <= currentAudioPts ? 0 : 1; 906 if (1 == cAVIdx && prev_seek_time_sec >= 0 ) 907 { 908 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); 909 prev_seek_time_sec = -1; 910 wrapped_avcodec_flush_buffers(1); 992 if (prev_seek_time_sec >= 0) 993 { 994 if (multiContextLastPts[0] != INVALID_PTS_VALUE) { 995 int64_t target = av_rescale(multiContextLastPts[0], AV_TIME_BASE, 90000); 996 avformat_seek_file(avContextTab[1], -1, INT64_MIN, target, INT64_MAX, 0); 997 prev_seek_time_sec = -1; 998 wrapped_avcodec_flush_buffers(1); 999 cAVIdx = 1; 1000 } else { 1001 cAVIdx = 0; 1002 } 1003 } else { 1004 if (multiContextLastPts[0] != INVALID_PTS_VALUE && multiContextLastPts[1] != INVALID_PTS_VALUE) { 1005 cAVIdx = multiContextLastPts[0] < multiContextLastPts[1] ? 0 : 1; 1006 } else { 1007 cAVIdx = !cAVIdx; 1008 } 911 1009 } 912 1010 } … … 916 1014 } 917 1015 } 918 1016 1017 if (bufferSize > 0) 1018 { 1019 LinuxDvbBuffSetStamp(stamp); 1020 } 919 1021 if (!isWaitingForFinish && (ffmpegStatus = av_read_frame(avContextTab[cAVIdx], &packet)) == 0 ) 920 1022 { … … 927 1029 int32_t pid = avContextTab[cAVIdx]->streams[packet.stream_index]->id; 928 1030 1031 multiContextLastPts[cAVIdx] = calcPts(cAVIdx, avContextTab[cAVIdx]->streams[packet.stream_index], packet.pts); 1032 ffmpeg_printf(200, "Ctx %d PTS: %"PRId64" PTS[1] %"PRId64"\n", cAVIdx, multiContextLastPts[cAVIdx], multiContextLastPts[1]); 1033 929 1034 reset_finish_timeout(); 930 931 if (context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack) < 0) 932 { 933 ffmpeg_err("error getting video track\n"); 1035 if(avContextTab[cAVIdx]->streams[packet.stream_index]->discard != AVDISCARD_ALL) 1036 { 1037 if (context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack) < 0) 1038 { 1039 ffmpeg_err("error getting video track\n"); 1040 } 1041 1042 if (context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack) < 0) 1043 { 1044 ffmpeg_err("error getting audio track\n"); 1045 } 1046 1047 if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0) 1048 { 1049 ffmpeg_err("error getting subtitle track\n"); 1050 } 1051 } 1052 else 1053 { 1054 ffmpeg_printf(1, "SKIP DISCARDED PACKET packed_size[%d] stream_index[%d] pid[%d]\n", packet.size, (int)packet.stream_index, pid); 934 1055 } 935 1056 936 if (context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack) < 0)937 {938 ffmpeg_err("error getting audio track\n");939 }940 941 if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0)942 {943 ffmpeg_err("error getting subtitle track\n");944 }945 946 1057 ffmpeg_printf(200, "packet.size %d - index %d\n", packet.size, pid); 947 1058 … … 950 1061 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56, 34, 100) 951 1062 AVCodecContext *codec_context = videoTrack->avCodecCtx; 952 if (codec_context && codec_context->codec_id == AV_CODEC_ID_MPEG4 && NULL != mpeg4p2_bsf_context) 953 { 954 // should never happen, if it does print error and exit immediately, so we can easily spot it 955 if (filter_packet(mpeg4p2_bsf_context, codec_context, &packet) < 0) 956 { 957 ffmpeg_err("cannot filter mpegp2 packet\n"); 958 exit(1); 959 } 960 if (mpeg4p2_write_packet(context, &mpeg4p2_context, videoTrack, cAVIdx, ¤tVideoPts, &latestPts, &packet) < 0) 961 { 962 ffmpeg_err("cannot write mpeg4p2 packet\n"); 963 exit(1); 964 } 1063 if (codec_context && codec_context->codec_id == AV_CODEC_ID_MPEG4 && NULL != mpeg4p2_context) 1064 { 1065 mpeg4p2_write_packet(context, mpeg4p2_context, videoTrack, cAVIdx, ¤tVideoPts, &latestPts, &packet); 965 1066 update_max_injected_pts(latestPts); 966 1067 } … … 977 1078 #endif 978 1079 { 979 uint8_t skipPacket = 0;1080 bool skipPacket = false; 980 1081 currentVideoPts = videoTrack->pts = pts = calcPts(cAVIdx, videoTrack->stream, packet.pts); 981 1082 videoTrack->dts = dts = calcPts(cAVIdx, videoTrack->stream, packet.dts); … … 999 1100 // skip already injected VIDEO packet 1000 1101 ffmpeg_printf(200, "skip already injected VIDEO packet\n"); 1001 skipPacket = 1;1102 skipPacket = true; 1002 1103 } 1003 1104 } … … 1006 1107 // skip VIDEO packet with unknown DTS 1007 1108 ffmpeg_printf(200, "skip VIDEO packet with unknown DTS\n"); 1008 skipPacket = 1;1109 skipPacket = true; 1009 1110 } 1010 1111 } … … 1017 1118 } 1018 1119 1019 ffmpeg_printf(200, "VideoTrack index = %d % lld\n",pid, currentVideoPts);1120 ffmpeg_printf(200, "VideoTrack index = %d %"PRId64"\n",pid, currentVideoPts); 1020 1121 1021 1122 avOut.data = packet.data; … … 1036 1137 } 1037 1138 1038 if ( context->output->video->Write(context, &avOut) < 0)1139 if (Write(context->output->video->Write, context, &avOut, pts) < 0) 1039 1140 { 1040 1141 ffmpeg_err("writing data to video device failed\n"); … … 1089 1190 pcmExtradata.sample_rate = get_codecpar(audioTrack->stream)->sample_rate; 1090 1191 pcmExtradata.bit_rate = get_codecpar(audioTrack->stream)->bit_rate; 1091 pcmExtradata.ffmpeg_codec_id = get_codecpar(audioTrack->stream)->codec_id; 1192 pcmExtradata.block_align = get_codecpar(audioTrack->stream)->block_align; 1193 pcmExtradata.frame_size = get_codecpar(audioTrack->stream)->frame_size; 1194 1195 pcmExtradata.codec_id = get_codecpar(audioTrack->stream)->codec_id; 1092 1196 pcmExtradata.bResampling = restart_audio_resampling; 1093 1197 … … 1112 1216 avOut.type = "audio"; 1113 1217 1114 if ( context->output->audio->Write(context, &avOut) < 0)1218 if (Write(context->output->audio->Write, context, &avOut, pts) < 0) 1115 1219 { 1116 1220 ffmpeg_err("(raw pcm) writing data to audio device failed\n"); … … 1220 1324 out_sample_rate = *rate ? *rate : 44100; 1221 1325 } 1222 1326 1223 1327 swr = swr_alloc(); 1224 1328 out_channels = c->channels; 1225 1329 1226 1330 if (c->channel_layout == 0) 1227 1331 { … … 1271 1375 continue; 1272 1376 } 1273 int64_t next_in_pts = av_rescale( av_frame_get_best_effort_timestamp(decoded_frame),1377 int64_t next_in_pts = av_rescale(wrapped_frame_get_best_effort_timestamp(decoded_frame), 1274 1378 ((AVStream*) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate, 1275 1379 ((AVStream*) audioTrack->stream)->time_base.den); … … 1288 1392 // The data described by the sample format is always in native-endian order 1289 1393 #ifdef WORDS_BIGENDIAN 1290 pcmExtradata. ffmpeg_codec_id = AV_CODEC_ID_PCM_S16BE;1394 pcmExtradata.codec_id = AV_CODEC_ID_PCM_S16BE; 1291 1395 #else 1292 pcmExtradata. ffmpeg_codec_id = AV_CODEC_ID_PCM_S16LE;1396 pcmExtradata.codec_id = AV_CODEC_ID_PCM_S16LE; 1293 1397 #endif 1294 1398 … … 1307 1411 avOut.type = "audio"; 1308 1412 1309 if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0)1413 if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0) 1310 1414 { 1311 1415 ffmpeg_err("writing data to audio device failed\n"); … … 1317 1421 { 1318 1422 ffmpeg_printf(200, "write audio aac\n"); 1319 ffmpeg_printf(200, "> >>>>>> %x %x %x %x %x %x\n", packet.data[0], packet.data[1], packet.data[2], packet.data[3], packet.data[4], packet.data[5], packet.data[6]);1423 ffmpeg_printf(200, "> %hhx %hhx %hhx %hhx %x %hhx %hhx\n", packet.data[0], packet.data[1], packet.data[2], packet.data[3], packet.data[4], packet.data[5], packet.data[6]); 1320 1424 1321 1425 avOut.data = packet.data; … … 1330 1434 avOut.type = "audio"; 1331 1435 1332 if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0)1436 if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0) 1333 1437 { 1334 1438 ffmpeg_err("(aac) writing data to audio device failed\n"); 1439 } 1440 } 1441 else if (pcmExtradata.codec_id == AV_CODEC_ID_VORBIS || pcmExtradata.codec_id == AV_CODEC_ID_OPUS || 1442 pcmExtradata.codec_id == AV_CODEC_ID_WMAV1 || pcmExtradata.codec_id == AV_CODEC_ID_WMAV2 || 1443 pcmExtradata.codec_id == AV_CODEC_ID_WMAPRO || pcmExtradata.codec_id == AV_CODEC_ID_WMALOSSLESS) { 1444 avOut.data = packet.data; 1445 avOut.len = packet.size; 1446 avOut.pts = pts; 1447 avOut.extradata = (uint8_t *) &pcmExtradata; 1448 avOut.extralen = sizeof(pcmExtradata); 1449 avOut.frameRate = 0; 1450 avOut.timeScale = 0; 1451 avOut.width = 0; 1452 avOut.height = 0; 1453 avOut.type = "audio"; 1454 1455 pcmExtradata.private_data = pAudioExtradata; 1456 pcmExtradata.private_size = audioExtradataSize; 1457 1458 if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0) { 1459 ffmpeg_err("writing data to audio device failed\n"); 1335 1460 } 1336 1461 } … … 1348 1473 avOut.type = "audio"; 1349 1474 1350 if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0)1475 if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0) 1351 1476 { 1352 1477 ffmpeg_err("writing data to audio device failed\n"); … … 1371 1496 } 1372 1497 1373 if (duration > 0) 1374 { 1375 // printf("[LIBEPLAYER3/FFMPEGThread] start\n"); 1376 1498 if (duration > 0 || duration == -1) 1499 { 1377 1500 SubtitleOut_t subOut; 1378 1501 memset(&subOut, 0, sizeof(subOut)); 1379 1502 subOut.trackId = pid; 1380 1503 subOut.data = (uint8_t *)packet.data; 1504 subOut.len = packet.size; 1381 1505 subOut.pts = pts; 1382 1506 subOut.durationMS = duration; 1383 //obi 1384 tmptrackId = pid; 1385 tmpdata = (uint8_t *)packet.data; 1386 // tmpdata = (uint8_t *)&packet.data; 1387 //tmplen; 1388 tmppts = pts; 1389 tmpduration = duration; 1390 tmpdata = ostrcat(subOut.data, NULL, 0, 0); 1391 1392 //*tmptype; 1393 // printf("[LIBEPLAYER3/FFMPEGThread] set tmpdata=%s\n", tmpdata); 1394 // printf("[LIBEPLAYER3/FFMPEGThread] set tmppts=%lld\n", tmppts); 1395 // printf("[LIBEPLAYER3/FFMPEGThread] set tmpduration=%lld\n", tmpduration); 1396 //obi (end) 1397 1398 if (context->output->subtitle->Write(context, &subOut) < 0) 1507 subOut.extradata = get_codecpar(stream)->extradata; 1508 subOut.extralen = get_codecpar(stream)->extradata_size; 1509 subOut.width = get_codecpar(stream)->width;; 1510 subOut.height = get_codecpar(stream)->height;; 1511 1512 //obi 1513 // printf("[LIBEPLAYER3/FFMPEGThread] start\n"); 1514 tmptrackId = pid; 1515 tmpdata = (uint8_t *)packet.data; 1516 // tmpdata = (uint8_t *)&packet.data; 1517 //tmplen; 1518 tmppts = pts; 1519 tmpduration = duration; 1520 tmpdata = ostrcat(subOut.data, NULL, 0, 0); 1521 1522 //*tmptype; 1523 // printf("[LIBEPLAYER3/FFMPEGThread] set tmpdata=%s\n", tmpdata); 1524 // printf("[LIBEPLAYER3/FFMPEGThread] set tmppts=%lld\n", tmppts); 1525 // printf("[LIBEPLAYER3/FFMPEGThread] set tmpduration=%lld\n", tmpduration); 1526 //obi (end) 1527 1528 if (Write(context->output->subtitle->Write, context, &subOut, pts) < 0) 1399 1529 { 1400 1530 ffmpeg_err("writing data to teletext fifo failed\n"); 1401 1531 } 1402 //obi 1403 char* tmpstr = NULL; 1404 tmpstr = ostrcat(tmpstr, "duration=", 1, 0); 1405 tmpstr = ostrcat(tmpstr, ollutoa(tmpduration), 1, 1); 1406 tmpstr = ostrcat(tmpstr, ";pts=", 1, 0);; 1407 tmpstr = ostrcat(tmpstr, ollutoa(tmppts), 1, 0);; 1408 tmpstr = ostrcat(tmpstr, ";trackid=", 1, 0);; 1409 tmpstr = ostrcat(tmpstr, oitoa(tmptrackId), 1, 0); 1410 tmpstr = ostrcat(tmpstr, ";subtext=", 1, 0);; 1411 tmpstr = ostrcat(tmpstr, tmpdata, 1, 0);; 1412 1413 free(subtext), subtext = NULL; 1414 subtext = ostrcat(subtext, tmpstr, 1, 0); 1415 free(tmpstr), tmpstr = NULL; 1416 1417 // tmpduration = 0; 1418 tmppts = 0; 1419 tmptrackId = 0; 1420 1421 // printf("[LIBEPLAYER3/FFMPEGThread] set subtext: %s\n", subtext); 1422 //obi (end) 1532 //obi 1533 char* tmpstr = NULL; 1534 tmpstr = ostrcat(tmpstr, "duration=", 1, 0); 1535 tmpstr = ostrcat(tmpstr, ollutoa(tmpduration), 1, 1); 1536 tmpstr = ostrcat(tmpstr, ";pts=", 1, 0);; 1537 tmpstr = ostrcat(tmpstr, ollutoa(tmppts), 1, 0);; 1538 tmpstr = ostrcat(tmpstr, ";trackid=", 1, 0);; 1539 tmpstr = ostrcat(tmpstr, oitoa(tmptrackId), 1, 0); 1540 tmpstr = ostrcat(tmpstr, ";subtext=", 1, 0);; 1541 tmpstr = ostrcat(tmpstr, tmpdata, 1, 0);; 1542 1543 free(subtext), subtext = NULL; 1544 subtext = ostrcat(subtext, tmpstr, 1, 0); 1545 free(tmpstr), tmpstr = NULL; 1546 1547 // tmpduration = 0; 1548 tmppts = 0; 1549 tmptrackId = 0; 1550 1551 // printf("[LIBEPLAYER3/FFMPEGThread] set subtext: %s\n", subtext); 1552 //obi (end) 1553 1423 1554 } 1424 1555 } … … 1460 1591 { 1461 1592 seek_target_bytes = 0; 1462 do_seek_target_bytes = 1;1593 do_seek_target_bytes = true; 1463 1594 bEndProcess = 0; 1464 1595 } … … 1468 1599 if( 0 == container_ffmpeg_get_length(context, &tmpLength) && tmpLength > 0 && get_play_pts() > 0) 1469 1600 { 1470 #if defined(TS_BYTES_SEEKING) && TS_BYTES_SEEKING 1471 if (avContextTab[0]->iformat->flags & AVFMT_TS_DISCONT) 1472 { 1473 seek_target_bytes = 0; 1474 do_seek_target_bytes = 1; 1475 } 1476 else 1477 #endif 1478 { 1479 seek_target_seconds = 0; 1480 do_seek_target_seconds = 1; 1481 } 1601 seek_target_seconds = 0; 1602 do_seek_target_seconds = 1; 1603 1482 1604 bEndProcess = 0; 1483 1605 context->output->Command(context, OUTPUT_CLEAR, NULL); … … 1516 1638 1517 1639 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56, 34, 100) 1518 mpeg4p2_context_reset(&mpeg4p2_context); 1519 if (NULL != mpeg4p2_bsf_context) 1520 { 1521 av_bitstream_filter_close(mpeg4p2_bsf_context); 1522 } 1640 mpeg4p2_context_close(mpeg4p2_context); 1523 1641 #endif 1524 1642 … … 1538 1656 PlaybackHandler_t *p = (PlaybackHandler_t *)ctx; 1539 1657 //obi 1540 //return p->abortRequested || PlaybackDieNow(0);1541 return p->abortRequested;1658 return p->abortRequested || PlaybackDieNow(0); 1659 // return p->abortRequested; 1542 1660 //obi (end) 1543 1661 } 1544 1662 1545 #ifdef SAM_CUSTOM_IO 1663 #ifdef USE_CUSTOM_IO 1664 typedef struct CustomIOCtx_t 1665 { 1666 FILE *pFile; 1667 FILE *pMoovFile; 1668 int64_t iOffset; 1669 1670 char *szFile; 1671 uint64_t iFileSize; 1672 char *szMoovAtomFile; 1673 uint64_t iMoovAtomOffset; 1674 } CustomIOCtx_t; 1675 1676 CustomIOCtx_t* custom_io_tab[IPTV_AV_CONTEXT_MAX_NUM] = {NULL, NULL}; 1677 1546 1678 int SAM_ReadFunc(void *ptr, uint8_t *buffer, int lSize) 1547 1679 { 1548 size_t ret = fread ( (void *) buffer, (size_t) 1, (size_t) lSize, (FILE *)ptr ); 1549 return (int)ret; 1680 CustomIOCtx_t *io = (CustomIOCtx_t *)ptr; 1681 int ret = 0; 1682 1683 if (!io->pMoovFile) 1684 { 1685 ret = (int)fread( (void *) buffer, (size_t) 1, (size_t) lSize, io->pFile ); 1686 } 1687 else 1688 { 1689 if (io->iOffset < io->iMoovAtomOffset) 1690 { 1691 ret = (int)fread( (void *) buffer, (size_t) 1, (size_t) lSize, io->pFile ); 1692 buffer += ret; 1693 lSize -= ret; 1694 } 1695 1696 if (io->iOffset + ret >= io->iMoovAtomOffset) 1697 { 1698 if (ret) 1699 { 1700 if (fseeko(io->pMoovFile, io->iOffset + ret - io->iMoovAtomOffset, SEEK_SET)) 1701 { 1702 // something goes wrong 1703 ffmpeg_err("fseeko on moov atom file fail \n"); 1704 lSize = 0; 1705 } 1706 } 1707 1708 ret += (int)fread( (void *) buffer, (size_t) 1, (size_t) lSize, io->pMoovFile ); 1709 } 1710 1711 io->iOffset += ret; 1712 } 1713 return ret; 1550 1714 } 1551 1715 1552 1716 // whence: SEEK_SET, SEEK_CUR, SEEK_END (like fseek) and AVSEEK_SIZE 1553 int64_t SAM_SeekFunc(void *ptr, int64_t pos, int whence)1717 int64_t SAM_SeekFunc(void *ptr, int64_t pos, int whence) 1554 1718 { 1555 if( AVSEEK_SIZE == whence ) 1556 { 1557 return -1; 1558 } 1559 int ret = fseeko((FILE *)ptr, (off_t)pos, whence); 1560 if(0 == ret) 1561 { 1562 return (off_t)ftello((FILE *)ptr); 1719 CustomIOCtx_t *io = (CustomIOCtx_t *)ptr; 1720 int64_t ret = -1; 1721 if (!io->pMoovFile) 1722 { 1723 if( AVSEEK_SIZE != whence ) 1724 { 1725 ret = (int64_t)fseeko(io->pFile, (off_t)pos, whence); 1726 if(0 == ret) 1727 { 1728 ret = (int64_t)ftello(io->pFile); 1729 } 1730 } 1731 } 1732 else 1733 { 1734 switch(whence) 1735 { 1736 case SEEK_SET: 1737 ret = pos; 1738 break; 1739 case SEEK_CUR: 1740 ret += pos; 1741 break; 1742 case SEEK_END: 1743 ret = io->iFileSize + pos; 1744 break; 1745 case AVSEEK_SIZE: 1746 return io->iFileSize; 1747 default: 1748 return -1; 1749 } 1750 1751 if (ret >= 0 && ret <= io->iFileSize) 1752 { 1753 if (ret < io->iMoovAtomOffset) 1754 { 1755 if(!fseeko(io->pFile, (off_t)ret, SEEK_SET)) 1756 io->iOffset = ret; 1757 else 1758 ret = -1; 1759 } 1760 else 1761 { 1762 if(!fseeko(io->pMoovFile, (off_t)(ret - io->iMoovAtomOffset), SEEK_SET)) 1763 io->iOffset = ret; 1764 else 1765 ret = -1; 1766 } 1767 } 1768 else 1769 { 1770 ret = -1; 1771 } 1563 1772 } 1564 1773 return ret; 1565 1774 } 1566 1775 1567 AVIOContext* container_ffmpeg_get_avio_context(char *filename, size_t avio_ctx_buffer_size) 1568 { 1569 if(strstr(filename, "file://") == filename) 1570 { 1571 filename += 7; 1572 } 1776 AVIOContext* container_ffmpeg_get_avio_context(CustomIOCtx_t *custom_io, size_t avio_ctx_buffer_size) 1777 { 1778 if(strstr(custom_io->szFile, "file://") == custom_io->szFile) 1779 custom_io->szFile += 7; 1780 1781 custom_io->pFile = fopen(custom_io->szFile, "rb"); 1782 if(NULL == custom_io->pFile) 1783 { 1784 return NULL; 1785 } 1786 1787 if (custom_io->szMoovAtomFile && custom_io->szMoovAtomFile[0] != '\0') 1788 { 1789 if(strstr(custom_io->szMoovAtomFile, "file://") == custom_io->szMoovAtomFile) 1790 custom_io->szMoovAtomFile += 7; 1573 1791 1574 FILE *pFile = fopen(filename, "rb"); 1575 if(NULL == pFile) 1576 { 1792 custom_io->pMoovFile = fopen(custom_io->szMoovAtomFile, "rb"); 1793 if(NULL == custom_io->pMoovFile) 1794 { 1795 fclose(custom_io->pFile); 1577 1796 return NULL; 1578 1797 } 1579 1580 AVIOContext *avio_ctx = NULL; 1581 uint8_t *avio_ctx_buffer = NULL; 1582 1583 avio_ctx_buffer = av_malloc(avio_ctx_buffer_size); 1584 if (!avio_ctx_buffer) 1585 { 1586 return NULL; 1587 } 1588 avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 0, pFile, &SAM_ReadFunc, NULL, &SAM_SeekFunc); 1589 if (!avio_ctx) 1590 { 1591 return NULL; 1592 } 1593 return avio_ctx; 1798 } 1799 1800 AVIOContext *avio_ctx = NULL; 1801 uint8_t *avio_ctx_buffer = NULL; 1802 1803 avio_ctx_buffer = av_malloc(avio_ctx_buffer_size); 1804 if (!avio_ctx_buffer) 1805 { 1806 return NULL; 1807 } 1808 avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 0, custom_io, &SAM_ReadFunc, NULL, &SAM_SeekFunc); 1809 if (!avio_ctx) 1810 { 1811 return NULL; 1812 } 1813 return avio_ctx; 1594 1814 } 1595 1815 #endif 1596 1816 1597 int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, int32_t AVIdx)1817 int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uint64_t fileSize, char *moovAtomFile, uint64_t moovAtomOffset, int32_t AVIdx) 1598 1818 { 1599 1819 int32_t err = 0; … … 1603 1823 avContextTab[AVIdx]->interrupt_callback.opaque = context->playback; 1604 1824 1605 #ifdef SAM_CUSTOM_IO1825 #ifdef USE_CUSTOM_IO 1606 1826 if(0 == strstr(filename, "://") || 1607 1827 0 == strncmp(filename, "file://", 7)) 1608 1828 { 1609 AVIOContext *avio_ctx = container_ffmpeg_get_avio_context(filename, 4096); 1829 AVIOContext *avio_ctx = NULL; 1830 custom_io_tab[AVIdx] = malloc(sizeof(CustomIOCtx_t)); 1831 sizeof(custom_io_tab[AVIdx], 0x00, sizeof(CustomIOCtx_t)); 1832 1833 custom_io_tab[AVIdx]->szFile = filename; 1834 custom_io_tab[AVIdx]->iFileSize = fileSize; 1835 custom_io_tab[AVIdx]->szMoovAtomFile = moovAtomFile; 1836 custom_io_tab[AVIdx]->iMoovAtomOffset = moovAtomOffset; 1837 1838 avio_ctx = container_ffmpeg_get_avio_context(custom_io_tab[AVIdx], 4096); 1610 1839 if(avio_ctx) 1611 1840 { … … 1615 1844 else 1616 1845 { 1846 free(custom_io_tab[AVIdx]); 1847 custom_io_tab[AVIdx] = NULL; 1617 1848 return cERR_CONTAINER_FFMPEG_OPEN; 1618 1849 } … … 1620 1851 #endif 1621 1852 1853 AVDictionary *avio_opts = NULL; 1622 1854 AVDictionary **pavio_opts = NULL; 1855 av_dict_copy(&avio_opts, g_avio_opts, 0); 1856 1623 1857 eRTMPProtoImplType rtmpProtoImplType = RTMP_NONE; 1624 1858 uint8_t numOfRTMPImpl = 0; … … 1837 2071 av_dict_set(&avio_opts, "timeout", "20000000", 0); //20sec 1838 2072 //obi 2073 /* 1839 2074 char* cookie = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL, *tmpstr4 = NULL, *headers = NULL, *useragent = NULL; 1840 2075 int count = 0, count1 = 0, count2 = 0, count3 = 0, i = 0, i1 = 0, i2 = 0, i3 = 0, usetslivemode = 0; … … 1989 2224 context->playback->isTSLiveMode = 1; 1990 2225 } 2226 */ 1991 2227 //obi (end) 1992 2228 … … 1999 2235 } 2000 2236 } 2001 2237 2002 2238 pavio_opts = &avio_opts; 2003 2239 … … 2019 2255 ffmpeg_err("avformat_open_input failed %d (%s)\n", err, filename); 2020 2256 av_strerror(err, error, 512); 2021 fprintf(stderr,"{\"FF_ERROR\":{\"msg\":\"%s\",\"code\":%i}}\n", error, err);2257 E2iSendMsg("{\"FF_ERROR\":{\"msg\":\"%s\",\"code\":%i}}\n", error, err); 2022 2258 2023 2259 if(avio_opts != NULL) … … 2134 2370 2135 2371 /* initialize ffmpeg */ 2136 avcodec_register_all(); 2137 av_register_all(); 2372 wrapped_register_all(); 2138 2373 avformat_network_init(); 2139 2374 2375 #if FFMPEG_DEBUG_LEVEL >= 10 2376 av_log_set_level( AV_LOG_DEBUG ); 2377 #else 2378 av_log_set_callback( ffmpeg_silen_callback ); 2379 #endif 2380 2140 2381 //obi 2382 /* 2141 2383 char* tmpstr = NULL; 2142 2384 tmpstr = readfiletomem("/mnt/config/titan.cfg", 1); … … 2146 2388 av_log_set_callback(ffmpeg_silen_callback); 2147 2389 free(tmpstr), tmpstr = NULL; 2148 //obi (end) 2149 // SULGE DEBUG ENABLED 2150 // make ffmpeg silen 2151 //av_log_set_level( AV_LOG_DEBUG ); 2152 //av_log_set_callback(ffmpeg_silen_callback); 2153 2390 */ 2391 //obi (end) 2392 2154 2393 context->playback->abortRequested = 0; 2155 int32_t res = container_ffmpeg_init_av_context(context, playFilesNames->szFirstFile, 0); 2394 int32_t res = container_ffmpeg_init_av_context(context, playFilesNames->szFirstFile, playFilesNames->iFirstFileSize, \ 2395 playFilesNames->szFirstMoovAtomFile, playFilesNames->iFirstMoovAtomOffset, 0); 2156 2396 if(0 != res) 2157 2397 { … … 2159 2399 } 2160 2400 2161 if(playFilesNames->szSecondFile) 2162 { 2163 res = container_ffmpeg_init_av_context(context, playFilesNames->szSecondFile, 1); 2401 if(playFilesNames->szSecondFile && playFilesNames->szSecondFile[0] != '\0') 2402 { 2403 res = container_ffmpeg_init_av_context(context, playFilesNames->szSecondFile, playFilesNames->iSecondFileSize, \ 2404 playFilesNames->szSecondMoovAtomFile, playFilesNames->iSecondMoovAtomOffset, 1); 2164 2405 } 2165 2406 … … 2173 2414 isContainerRunning = 1; 2174 2415 res = container_ffmpeg_update_tracks(context, playFilesNames->szFirstFile, 1); 2175 2176 2416 //obi 2177 //ReadSubtitles(context, playFilesNames->szFirstFile);2417 // ReadSubtitles(context, playFilesNames->szFirstFile); 2178 2418 //obi (end) 2179 2419 return res; … … 2182 2422 int32_t container_ffmpeg_update_tracks(Context_t *context, char *filename, int32_t initial) 2183 2423 { 2184 Track_t *audioTrack = NULL; 2185 Track_t *subtitleTrack = NULL; 2424 Track_t *currAudioTrack = NULL; 2425 Track_t *currSubtitleTrack = NULL; 2426 uint32_t addedVideoTracksCount = 0; 2186 2427 2187 2428 if (terminating) … … 2190 2431 } 2191 2432 2433 getMutex(__FILE__, __FUNCTION__,__LINE__); 2434 2192 2435 if (initial && context->manager->subtitle) 2193 2436 { 2194 context->manager->subtitle->Command(context, MANAGER_GET_TRACK, & subtitleTrack);2437 context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &currSubtitleTrack); 2195 2438 } 2196 2439 2197 2440 if (context->manager->audio) 2198 2441 { 2199 context->manager->audio->Command(context, MANAGER_GET_TRACK, & audioTrack);2442 context->manager->audio->Command(context, MANAGER_GET_TRACK, &currAudioTrack); 2200 2443 } 2201 2444 … … 2216 2459 } 2217 2460 #endif 2218 2219 2461 2220 2462 ffmpeg_printf(20, "dump format\n"); … … 2294 2536 } 2295 2537 2296 if (!isStreamFromSelProg) 2538 if (!isStreamFromSelProg) { 2539 stream->discard = AVDISCARD_ALL; 2540 ffmpeg_printf(1, "cAVIdx[%d]: add DISCARD flag to stream index[%d]\n", cAVIdx, stream->index); 2297 2541 continue; // skip this stream 2542 } 2298 2543 } 2299 2544 … … 2328 2573 case AVMEDIA_TYPE_VIDEO: 2329 2574 ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n", get_codecpar(stream)->codec_type); 2330 2575 // do not discard any stream from second context 2576 stream->discard = 0 == cAVIdx ? AVDISCARD_ALL : AVDISCARD_DEFAULT; /* by default we discard all video streams */ 2331 2577 if (encoding != NULL) 2332 2578 { … … 2373 2619 } 2374 2620 2375 ffmpeg_printf(10, "bit_rate [% d]\n", get_codecpar(stream)->bit_rate);2621 ffmpeg_printf(10, "bit_rate [%"PRId64"]\n", get_codecpar(stream)->bit_rate); 2376 2622 ffmpeg_printf(10, "time_base.den [%d]\n", stream->time_base.den); 2377 2623 ffmpeg_printf(10, "time_base.num [%d]\n", stream->time_base.num); … … 2402 2648 track.avCodecCtx = wrapped_avcodec_get_context(cAVIdx, stream); 2403 2649 } 2404 ffmpeg_printf(1, "cAVIdx[%d]: MANAGER_ADD track VIDEO\n" );2650 ffmpeg_printf(1, "cAVIdx[%d]: MANAGER_ADD track VIDEO\n", cAVIdx); 2405 2651 if( context->manager->video->Command(context, MANAGER_ADD, &track) < 0) 2406 2652 { 2407 2653 /* konfetti: fixme: is this a reason to return with error? */ 2408 2654 ffmpeg_err("failed to add track %d\n", n); 2655 } 2656 else 2657 { 2658 if (addedVideoTracksCount == 0) /* at now we can handle only first video track */ 2659 { 2660 stream->discard = AVDISCARD_DEFAULT; 2661 } 2662 addedVideoTracksCount += 1; 2409 2663 } 2410 2664 } … … 2417 2671 case AVMEDIA_TYPE_AUDIO: 2418 2672 ffmpeg_printf(10, "CODEC_TYPE_AUDIO %d\n",get_codecpar(stream)->codec_type); 2419 2673 // do not discard any stream from second context 2674 stream->discard = 0 == cAVIdx ? AVDISCARD_ALL : AVDISCARD_DEFAULT; 2420 2675 if (encoding != NULL) 2421 2676 { … … 2517 2772 int32_t object_type = 2; // LC 2518 2773 int32_t sample_index = aac_get_sample_rate_index(get_codecpar(stream)->sample_rate); 2519 int32_t chan_config = get_c odecpar(stream)->channels - 1;2774 int32_t chan_config = get_chan_config(get_codecpar(stream)->channels); 2520 2775 ffmpeg_printf(1,"aac object_type %d\n", object_type); 2521 2776 ffmpeg_printf(1,"aac sample_index %d\n", sample_index); 2522 2777 ffmpeg_printf(1,"aac chan_config %d\n", chan_config); 2523 2778 2779 int off = -1; 2524 2780 if (get_codecpar(stream)->extradata_size >= 2) 2525 2781 { 2526 2782 MPEG4AudioConfig m4ac; 2527 intoff = avpriv_mpeg4audio_get_config(&m4ac, get_codecpar(stream)->extradata, get_codecpar(stream)->extradata_size * 8, 1);2783 off = avpriv_mpeg4audio_get_config(&m4ac, get_codecpar(stream)->extradata, get_codecpar(stream)->extradata_size * 8, 1); 2528 2784 if (off >= 0) 2529 2785 { … … 2542 2798 ffmpeg_printf(1,"aac chan_config %d\n", chan_config); 2543 2799 2544 2800 if (off >= 0 && chan_config == 0) { // channel config must be send in the inband PCE 2801 track.aacbuf = malloc(AAC_HEADER_LENGTH + MAX_PCE_SIZE); 2802 2803 GetBitContext gb; 2804 PutBitContext pb; 2805 init_put_bits(&pb, track.aacbuf + AAC_HEADER_LENGTH, MAX_PCE_SIZE); 2806 init_get_bits8(&gb, get_codecpar(stream)->extradata, get_codecpar(stream)->extradata_size); 2807 skip_bits_long(&gb, off + 3); 2808 2809 put_bits(&pb, 3, 5); //ID_PCE 2810 track.aacbuflen = AAC_HEADER_LENGTH + (avpriv_copy_pce_data(&pb, &gb) + 3) / 8; 2811 flush_put_bits(&pb); 2812 } 2813 else { 2814 track.aacbuflen = AAC_HEADER_LENGTH; 2815 track.aacbuf = malloc(AAC_HEADER_LENGTH+1); 2816 } 2817 2545 2818 // https://wiki.multimedia.cx/index.php/ADTS 2546 2819 object_type -= 1; //ADTS - profile, the MPEG-4 Audio Object Type minus 1 2547 2548 track.aacbuflen = AAC_HEADER_LENGTH; 2549 track.aacbuf = malloc(8); 2820 2550 2821 track.aacbuf[0] = 0xFF; 2551 2822 track.aacbuf[1] = 0xF1; … … 2570 2841 2571 2842 } 2843 #ifdef __sh__ 2572 2844 else if(get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAV1 2573 2845 || get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAV2 … … 2576 2848 { 2577 2849 ffmpeg_printf(10,"Create WMA ExtraData\n"); 2578 uint16_t channels = get_codecpar(stream)->channels; 2579 uint32_t rate = get_codecpar(stream)->sample_rate; 2580 uint32_t bitrate = get_codecpar(stream)->bit_rate; 2581 uint16_t block_align = get_codecpar(stream)->block_align; 2582 uint16_t depth = get_codecpar(stream)->bits_per_coded_sample; 2583 uint32_t codec_data_size = get_codecpar(stream)->extradata_size; 2584 uint8_t *codec_data_pointer = get_codecpar(stream)->extradata; 2585 2850 2586 2851 // type_specific_data 2587 #define WMA_VERSION_1 0x1602588 #define WMA_VERSION_2_9 0x1612589 #define WMA_VERSION_9_PRO 0x1622590 #define WMA_LOSSLESS 0x1632591 2852 uint16_t codec_id = 0; 2592 2853 switch(get_codecpar(stream)->codec_id) … … 2594 2855 //TODO: What code for lossless ? 2595 2856 case AV_CODEC_ID_WMALOSSLESS: 2596 codec_id = WMA_LOSSLESS;2857 codec_id = 0x163; // WMA_LOSSLESS 2597 2858 break; 2598 2859 case AV_CODEC_ID_WMAPRO: 2599 codec_id = WMA_VERSION_9_PRO;2860 codec_id = 0x162; // WMA_VERSION_9_PRO 2600 2861 break; 2601 2862 case AV_CODEC_ID_WMAV2: 2602 codec_id = WMA_VERSION_2_9 ;2863 codec_id = 0x161; // WMA_VERSION_2_9 2603 2864 break; 2604 2865 case AV_CODEC_ID_WMAV1: 2605 2866 default: 2606 codec_id = WMA_VERSION_1;2867 codec_id = 0x160; // WMA_VERSION_1 2607 2868 break; 2608 2869 } 2609 #ifdef __sh__ 2870 2610 2871 track.aacbuflen = 104 + get_codecpar(stream)->extradata_size; 2611 2872 track.aacbuf = malloc(track.aacbuflen); … … 2675 2936 2676 2937 memcpy(track.aacbuf + 96, get_codecpar(stream)->extradata, get_codecpar(stream)->extradata_size); 2677 #else 2678 track.aacbuflen = 18 + get_codecpar(stream)->extradata_size; 2679 track.aacbuf = malloc(track.aacbuflen); 2680 memset (track.aacbuf, 0, track.aacbuflen); 2681 2682 uint8_t *data = track.aacbuf; 2683 /* codec tag */ 2684 *(data++) = codec_id & 0xff; 2685 *(data++) = (codec_id >> 8) & 0xff; 2686 /* channels */ 2687 *(data++) = channels & 0xff; 2688 *(data++) = (channels >> 8) & 0xff; 2689 /* sample rate */ 2690 *(data++) = rate & 0xff; 2691 *(data++) = (rate >> 8) & 0xff; 2692 *(data++) = (rate >> 16) & 0xff; 2693 *(data++) = (rate >> 24) & 0xff; 2694 /* byte rate */ 2695 bitrate /= 8; 2696 *(data++) = bitrate & 0xff; 2697 *(data++) = (bitrate >> 8) & 0xff; 2698 *(data++) = (bitrate >> 16) & 0xff; 2699 *(data++) = (bitrate >> 24) & 0xff; 2700 /* block align */ 2701 *(data++) = block_align & 0xff; 2702 *(data++) = (block_align >> 8) & 0xff; 2703 /* word size */ 2704 *(data++) = depth & 0xff; 2705 *(data++) = (depth >> 8) & 0xff; 2706 /* codec data size */ 2707 *(data++) = codec_data_size & 0xff; 2708 *(data++) = (codec_data_size >> 8) & 0xff; 2709 memcpy(data, codec_data_pointer, codec_data_size); 2938 2939 ffmpeg_printf(1, "aacbuf:\n"); 2940 track.have_aacheader = 1; 2941 } 2710 2942 #endif 2711 ffmpeg_printf(1, "aacbuf:\n");2712 //Hexdump(track.aacbuf, track.aacbuflen);2713 2714 //ffmpeg_printf(1, "priv_data:\n");2715 //Hexdump(get_codecpar(stream)->priv_data, track.aacbuflen);2716 2717 track.have_aacheader = 1;2718 }2719 2720 2943 if (context->manager->audio) 2721 2944 { 2722 ffmpeg_printf(1, "cAVIdx[%d]: MANAGER_ADD track AUDIO\n" );2945 ffmpeg_printf(1, "cAVIdx[%d]: MANAGER_ADD track AUDIO\n", cAVIdx); 2723 2946 if (context->manager->audio->Command(context, MANAGER_ADD, &track) < 0) 2724 2947 { … … 2741 2964 get_codecpar(stream)->codec_id != AV_CODEC_ID_SUBRIP && 2742 2965 get_codecpar(stream)->codec_id != AV_CODEC_ID_TEXT && 2743 get_codecpar(stream)->codec_id != AV_CODEC_ID_SRT) 2966 get_codecpar(stream)->codec_id != AV_CODEC_ID_SRT && 2967 get_codecpar(stream)->codec_id != AV_CODEC_ID_WEBVTT && 2968 ((get_codecpar(stream)->codec_id != AV_CODEC_ID_HDMV_PGS_SUBTITLE && 2969 get_codecpar(stream)->codec_id != AV_CODEC_ID_DVB_SUBTITLE && 2970 get_codecpar(stream)->codec_id != AV_CODEC_ID_XSUB) || 2971 !GetGraphicSubPath() || !GetGraphicSubPath()[0])) 2744 2972 { 2745 2973 ffmpeg_printf(10, "subtitle with not supported codec codec_id[%u]\n", (uint32_t)get_codecpar(stream)->codec_id); … … 2767 2995 } 2768 2996 2769 track.extraData = get_codecpar(stream)->extradata;2770 track.extraSize = get_codecpar(stream)->extradata_size;2771 2772 2997 ffmpeg_printf(1, "subtitle codec %d\n", get_codecpar(stream)->codec_id); 2773 2998 ffmpeg_printf(1, "subtitle width %d\n", get_codecpar(stream)->width); … … 2789 3014 case AVMEDIA_TYPE_NB: 2790 3015 default: 3016 stream->discard = AVDISCARD_ALL; 2791 3017 ffmpeg_err("not handled or unknown codec_type %d\n", get_codecpar(stream)->codec_type); 2792 3018 break; … … 2795 3021 2796 3022 } 2797 3023 3024 if (context->manager->audio) 3025 { 3026 Track_t *Tracks = NULL; 3027 int32_t TrackCount = 0; 3028 int32_t selTrackIdx = -1; 3029 3030 context->manager->audio->Command(context, MANAGER_REF_LIST, &Tracks); 3031 context->manager->audio->Command(context, MANAGER_REF_LIST_SIZE, &TrackCount); 3032 if (Tracks && TrackCount) 3033 { 3034 int32_t i; 3035 for (i=0; i < TrackCount; ++i) 3036 { 3037 if (Tracks[i].pending || Tracks[i].Id < 0) 3038 continue; 3039 3040 if (selTrackIdx == -1) 3041 selTrackIdx = i; 3042 3043 if (currAudioTrack && currAudioTrack->Id == Tracks[i].Id) 3044 { 3045 selTrackIdx = i; 3046 break; 3047 } 3048 } 3049 3050 if (selTrackIdx > -1) 3051 { 3052 ((AVStream*)Tracks[selTrackIdx].stream)->discard = AVDISCARD_DEFAULT; 3053 if (!currAudioTrack || currAudioTrack->Id != Tracks[selTrackIdx].Id ) 3054 { 3055 context->manager->audio->Command(context, MANAGER_SET, &Tracks[selTrackIdx].Id); 3056 } 3057 } 3058 } 3059 } 3060 3061 releaseMutex(__FILE__, __FUNCTION__,__LINE__); 2798 3062 return cERR_CONTAINER_FFMPEG_NO_ERROR; 2799 3063 } … … 2931 3195 } 2932 3196 2933 if( avio_opts != NULL)2934 { 2935 av_dict_free(& avio_opts);3197 if(g_avio_opts != NULL) 3198 { 3199 av_dict_free(&g_avio_opts); 2936 3200 } 2937 3201 … … 2951 3215 off_t current_pos = avio_tell(avContextTab[0]->pb); 2952 3216 2953 ffmpeg_printf(20, "seeking to position % lld(bytes)\n", pos);3217 ffmpeg_printf(20, "seeking to position %"PRId64" (bytes)\n", pos); 2954 3218 2955 3219 if (current_pos > pos) … … 2964 3228 } 2965 3229 2966 ffmpeg_printf(30, "current_pos after seek % lld\n", avio_tell(avContextTab[0]->pb));3230 ffmpeg_printf(30, "current_pos after seek %"PRId64"\n", avio_tell(avContextTab[0]->pb)); 2967 3231 2968 3232 return cERR_CONTAINER_FFMPEG_NO_ERROR; 2969 3233 } 2970 3234 2971 /* seeking relative to a given byteposition N seconds ->for reverse playback needed */ 2972 static int32_t container_ffmpeg_seek_rel(Context_t *context, off_t pos, int64_t pts, int64_t sec) 3235 static int32_t container_ffmpeg_seek(Context_t *context, int64_t sec, uint8_t absolute) 2973 3236 { 2974 3237 Track_t *videoTrack = NULL; 2975 3238 Track_t *audioTrack = NULL; 2976 3239 Track_t *current = NULL; 2977 seek_target_flag = 0;2978 2979 ffmpeg_printf(10, "seeking %f sec relativ to %lld\n", sec, pos);2980 2981 context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack);2982 context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack);2983 2984 if (videoTrack != NULL)2985 {2986 current = videoTrack;2987 }2988 else if (audioTrack != NULL)2989 {2990 current = audioTrack;2991 }2992 2993 if (current == NULL)2994 {2995 ffmpeg_err( "no track avaibale to seek\n");2996 return cERR_CONTAINER_FFMPEG_ERR;2997 }2998 2999 if (pos == -1)3000 {3001 pos = avio_tell(avContextTab[0]->pb);3002 }3003 3004 if (pts == -1)3005 {3006 pts = current->pts;3007 }3008 3009 if (sec < 0)3010 {3011 seek_target_flag |= AVSEEK_FLAG_BACKWARD;3012 }3013 3014 ffmpeg_printf(10, "iformat->flags %d\n", avContextTab[0]->iformat->flags);3015 #if defined(TS_BYTES_SEEKING) && TS_BYTES_SEEKING3016 if (avContextTab[0]->iformat->flags & AVFMT_TS_DISCONT)3017 {3018 if (avContextTab[0]->bit_rate)3019 {3020 sec *= avContextTab[0]->bit_rate / 8;3021 ffmpeg_printf(10, "bit_rate %d\n", avContextTab[0]->bit_rate);3022 }3023 else3024 {3025 sec *= 180000;3026 }3027 3028 pos += sec;3029 3030 if (pos < 0)3031 {3032 ffmpeg_err("end of file reached\n");3033 releaseMutex(__FILE__, __FUNCTION__,__LINE__);3034 return cERR_CONTAINER_FFMPEG_END_OF_FILE;3035 }3036 3037 ffmpeg_printf(10, "1. seeking to position %lld bytes ->sec %f\n", pos, sec);3038 3039 seek_target_bytes = pos;3040 do_seek_target_bytes = 1;3041 3042 return pos;3043 }3044 else3045 #endif3046 {3047 sec += pts / 90000;3048 3049 if (sec < 0)3050 {3051 sec = 0;3052 }3053 3054 ffmpeg_printf(10, "2. seeking to position %f sec ->time base %f %d\n", sec, av_q2d(((AVStream*) current->stream)->time_base), AV_TIME_BASE);3055 3056 seek_target_seconds = sec * AV_TIME_BASE;3057 do_seek_target_seconds = 1;3058 }3059 3060 releaseMutex(__FILE__, __FUNCTION__,__LINE__);3061 return cERR_CONTAINER_FFMPEG_NO_ERROR;3062 }3063 3064 static int32_t container_ffmpeg_seek(Context_t *context, int64_t sec, uint8_t absolute)3065 {3066 Track_t *videoTrack = NULL;3067 Track_t *audioTrack = NULL;3068 Track_t *current = NULL;3069 seek_target_flag = 0;3070 3240 3071 3241 if (!absolute) 3072 3242 { 3073 ffmpeg_printf(10, "seeking % fsec\n", sec);3243 ffmpeg_printf(10, "seeking %"PRId64" sec\n", sec); 3074 3244 if (sec == 0) 3075 3245 { … … 3090 3260 } 3091 3261 3092 ffmpeg_printf(10, "goto % dsec\n", sec);3262 ffmpeg_printf(10, "goto %"PRId64" sec\n", sec); 3093 3263 if (sec < 0) 3094 3264 { … … 3113 3283 } 3114 3284 3115 if (sec < 0)3116 {3117 seek_target_flag |= AVSEEK_FLAG_BACKWARD;3118 }3119 3120 getMutex(__FILE__, __FUNCTION__,__LINE__);3121 3122 3285 if (!context->playback || !context->playback->isPlaying) 3123 3286 { 3124 releaseMutex(__FILE__, __FUNCTION__,__LINE__);3125 3287 return cERR_CONTAINER_FFMPEG_NO_ERROR; 3126 3288 } 3127 3289 3128 ffmpeg_printf(10, "iformat->flags %d\n", avContextTab[0]->iformat->flags); 3129 #if defined(TS_BYTES_SEEKING) && TS_BYTES_SEEKING 3130 if (avContextTab[0]->iformat->flags & AVFMT_TS_DISCONT) 3131 { 3132 /* konfetti: for ts streams seeking frame per seconds does not work (why?). 3133 * I take this algo partly from ffplay.c. 3134 * 3135 * seeking per HTTP does still not work very good. forward seeks everytime 3136 * about 10 seconds, backward does not work. 3137 */ 3138 3139 off_t pos = avio_tell(avContextTab[0]->pb); 3140 3141 ffmpeg_printf(10, "pos %lld %d\n", pos, avContextTab[0]->bit_rate); 3142 3143 if (avContextTab[0]->bit_rate) 3144 { 3145 sec *= avContextTab[0]->bit_rate / 8; 3146 ffmpeg_printf(10, "bit_rate %d\n", avContextTab[0]->bit_rate); 3147 } 3148 else 3149 { 3150 sec *= 180000; 3151 } 3152 3153 pos = sec; 3154 3155 if (pos < 0) 3156 { 3157 pos = 0; 3158 } 3159 3160 ffmpeg_printf(10, "1. seeking to position %lld bytes ->sec %d\n", pos, sec); 3161 3162 seek_target_bytes = pos; 3163 do_seek_target_bytes = 1; 3164 3165 } 3166 else 3167 #endif 3168 { 3169 seek_target_seconds = sec * AV_TIME_BASE; 3170 do_seek_target_seconds = 1; 3171 } 3172 3173 releaseMutex(__FILE__, __FUNCTION__,__LINE__); 3290 getSeekMutex(); 3291 g_seek_target_seconds = sec * AV_TIME_BASE; 3292 g_do_seek_target_seconds = true; 3293 g_stamp = context->playback->stamp; 3294 releaseSeekMutex(); 3295 3174 3296 return cERR_CONTAINER_FFMPEG_NO_ERROR; 3175 3297 } … … 3232 3354 { 3233 3355 ffmpeg_printf(10, "track %d\n", *arg); 3356 getMutex(__FILE__, __FUNCTION__,__LINE__); 3357 if (context->manager->audio) 3358 { 3359 Track_t *Tracks = NULL; 3360 int32_t TrackCount = 0; 3361 3362 context->manager->audio->Command(context, MANAGER_REF_LIST, &Tracks); 3363 context->manager->audio->Command(context, MANAGER_REF_LIST_SIZE, &TrackCount); 3364 if (Tracks && TrackCount) 3365 { 3366 int32_t i; 3367 for (i=0; i < TrackCount; ++i) 3368 { 3369 // do not discard any stream from second context 3370 if (Tracks[i].AVIdx == 0) { 3371 ((AVStream*)Tracks[i].stream)->discard = Tracks[i].Id == *arg ? AVDISCARD_DEFAULT : AVDISCARD_ALL; 3372 } 3373 } 3374 } 3375 } 3376 releaseMutex(__FILE__, __FUNCTION__,__LINE__); 3234 3377 3235 3378 /* Hellmaster1024: nothing to do here!*/ 3236 int64_t sec = - 5;3379 int64_t sec = -1; 3237 3380 context->playback->Command(context, PLAYBACK_SEEK, (void*)&sec); 3238 3381 return cERR_CONTAINER_FFMPEG_NO_ERROR; … … 3248 3391 * but now we will not ignore subtitle frame 3249 3392 */ 3250 int64_t sec = - 5;3393 int64_t sec = -1; 3251 3394 context->playback->Command(context, PLAYBACK_SEEK, (void*)&sec); 3252 3395 //obi … … 3466 3609 break; 3467 3610 } 3468 //obi (end) 3611 //obi (end) 3469 3612 default: 3470 3613 ffmpeg_err("ContainerCmd %d not supported!\n", command); … … 3477 3620 } 3478 3621 3479 static char *FFMPEG_Capabilities[] = {"aac", "avi", "mkv", "mp4", "ts", "mov", "flv", "flac", "mp3", "mpg", "m2ts", "vob", "evo", "wmv","wma", "asf", "mp2", "m4v", "m4a", "fla", "divx", "dat", "mpeg", "trp", "mts", "vdr", "ogg", "wav", "wtv", "asx", "mvi", "png", "jpg", " ra", "ram", "rm", "3gp", "amr", "webm", "m3u8", "mpd", NULL };3622 static char *FFMPEG_Capabilities[] = {"aac", "avi", "mkv", "mp4", "ts", "mov", "flv", "flac", "mp3", "mpg", "m2ts", "vob", "evo", "wmv","wma", "asf", "mp2", "m4v", "m4a", "fla", "divx", "dat", "mpeg", "trp", "mts", "vdr", "ogg", "wav", "wtv", "asx", "mvi", "png", "jpg", "jpeg", "ra", "ram", "rm", "3gp", "amr", "rmvb", "rm", "webm", "opus", "m3u8", "mpd", NULL }; 3480 3623 3481 3624 Container_t FFMPEGContainer = { -
titan/libeplayer3/container/flv2mpeg4_ffmpeg.c
r42431 r44958 39 39 avOut.type = "video"; 40 40 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) 42 42 { 43 43 ffmpeg_err("writing data to video device failed\n"); -
titan/libeplayer3/container/mpeg4p2_ffmpeg.c
r42431 r44958 4 4 // 5 5 6 #define MPEG4P2_MAX_B_FRAMES_COUNT 5 7 6 // mpeg4_unpack_bframes 8 7 typedef struct 9 8 { 10 int b_frames_count; 11 int first_ip_frame_written; 12 int64_t packet_duration; 13 AVPacket *b_frames[MPEG4P2_MAX_B_FRAMES_COUNT]; 14 AVPacket *second_ip_frame; 9 const AVBitStreamFilter *bsf; 10 AVBSFContext *ctx; 15 11 } Mpeg4P2Context; 16 12 17 18 static void set_packet(AVPacket **pkt_dest, AVPacket *pkt_src) 13 static Mpeg4P2Context * mpeg4p2_context_open() 19 14 { 20 if (pkt_dest == NULL) 21 return; 22 if (*pkt_dest != NULL) 23 { 24 wrapped_packet_unref(*pkt_dest); 25 av_free(*pkt_dest); 15 Mpeg4P2Context *context = NULL; 16 const AVBitStreamFilter *bsf = av_bsf_get_by_name("mpeg4_unpack_bframes"); 17 if (bsf) { 18 context = malloc(sizeof(Mpeg4P2Context)); 19 if (context) { 20 memset(context, 0x00, sizeof(Mpeg4P2Context)); 21 context->bsf = bsf; 22 } 26 23 } 27 *pkt_dest = av_malloc(sizeof(AVPacket)); 28 av_copy_packet(*pkt_dest, pkt_src); 24 return context; 29 25 } 30 26 31 static int filter_packet(AVBitStreamFilterContext *bsf_ctx, AVCodecContext *enc_ctx, AVPacket *pkt)27 static void mpeg4p2_write(Context_t *ctx, Mpeg4P2Context *mpeg4p2_ctx, Track_t *track, int64_t start_time, int64_t *currentVideoPts, int64_t *latestPts, AVPacket *pkt) 32 28 { 33 int ret; 34 AVPacket new_pkt = *pkt; 35 ret = av_bitstream_filter_filter(bsf_ctx, enc_ctx, NULL, 36 &new_pkt.data, &new_pkt.size, 37 pkt->data, pkt->size, 38 pkt->flags & AV_PKT_FLAG_KEY); 39 if (ret == 0 && new_pkt.data != pkt->data) 40 { 41 if ((ret = av_copy_packet(&new_pkt, pkt)) < 0) 42 return -1; 43 ret = 1; 44 } 45 if (ret > 0) 46 { 47 pkt->side_data = NULL; 48 pkt->side_data_elems = 0; 49 wrapped_packet_unref(pkt); 50 new_pkt.buf = av_buffer_create(new_pkt.data, new_pkt.size, 51 av_buffer_default_free, NULL, 0); 52 if (!new_pkt.buf) 53 return -1; 54 } 55 if (ret < 0) 56 { 57 ffmpeg_err("Failed to filter bitstream with filter %s for stream %d with codec %s\n", 58 bsf_ctx->filter->name, pkt->stream_index, 59 avcodec_get_name(enc_ctx->codec_id)); 60 return -1; 61 } 62 *pkt = new_pkt; 63 return 0; 64 } 65 66 static void mpeg4p2_context_reset(Mpeg4P2Context *context) 67 { 68 if (context == NULL) 69 return; 70 int i; 71 for (i=0; i < MPEG4P2_MAX_B_FRAMES_COUNT; i++) 72 { 73 if (context->b_frames[i] != NULL) 74 { 75 wrapped_packet_unref(context->b_frames[i]); 76 av_free(context->b_frames[i]); 77 } 78 context->b_frames[i] = NULL; 79 } 80 if (context->second_ip_frame != NULL) 81 { 82 wrapped_packet_unref(context->second_ip_frame); 83 av_free(context->second_ip_frame); 84 } 85 context->second_ip_frame = NULL; 86 87 context->b_frames_count = 0; 88 context->first_ip_frame_written = 0; 89 context->packet_duration = 0; 90 } 91 92 static void mpeg4p2_write(Context_t *ctx, Track_t *track, int avContextIdx, int64_t *currentVideoPts, int64_t *latestPts, AVPacket *pkt) 93 { 94 *currentVideoPts = track->pts = calcPts(avContextIdx, track->stream, pkt->pts); 95 if ((*currentVideoPts > *latestPts) && (*currentVideoPts != INVALID_PTS_VALUE)) 96 { 29 *currentVideoPts = track->pts = doCalcPts(start_time, mpeg4p2_ctx->ctx->time_base_out, pkt->pts); 30 if ((*currentVideoPts > *latestPts) && (*currentVideoPts != INVALID_PTS_VALUE)) { 97 31 *latestPts = *currentVideoPts; 98 32 } 99 track->dts = calcPts(avContextIdx, track->stream, pkt->dts); 33 34 track->dts = doCalcPts(start_time, mpeg4p2_ctx->ctx->time_base_out, pkt->dts); 100 35 101 36 AudioVideoOut_t avOut; … … 104 39 avOut.pts = track->pts; 105 40 avOut.dts = track->dts; 106 avOut.extradata = track->extraData;107 avOut.extralen = track->extraSize;41 avOut.extradata = mpeg4p2_ctx->ctx->par_out->extradata; 42 avOut.extralen = mpeg4p2_ctx->ctx->par_out->extradata_size; 108 43 avOut.frameRate = track->frame_rate; 109 44 avOut.timeScale = track->TimeScale; … … 112 47 avOut.type = "video"; 113 48 114 if (ctx->output->video->Write(ctx, &avOut) < 0) 115 { 49 if (Write(ctx->output->video->Write, ctx, &avOut, avOut.pts) < 0) { 116 50 ffmpeg_err("writing data to video device failed\n"); 117 51 } 118 52 } 119 53 54 static int mpeg4p2_context_reset(Mpeg4P2Context *context) 55 { 56 int ret = 0; 57 if (context && context->ctx) { 58 // Flush 59 ret = av_bsf_send_packet(context->ctx, NULL); 60 if (ret == 0) { 61 AVPacket *pkt = NULL; 62 while ((ret = av_bsf_receive_packet(context->ctx, pkt)) == 0) { 63 wrapped_frame_unref(pkt); 64 } 65 } 66 av_bsf_free(&context->ctx); 67 } 68 69 return ret; 70 } 71 120 72 static int mpeg4p2_write_packet(Context_t *ctx, Mpeg4P2Context *mpeg4p2_ctx, Track_t *track, int cAVIdx, int64_t *pts_current, int64_t *pts_latest, AVPacket *pkt) 121 73 { 122 uint8_t *data = pkt->data;123 i nt data_len = pkt->size;124 int pos = 0;125 if (mpeg4p2_ctx->packet_duration == 0)126 {127 mpeg4p2_ctx->packet_duration = pkt->duration;128 }129 while (pos < data_len)130 {131 if (memcmp(&data[pos], "\x00\x00\x01\xb6", 4))132 {133 pos++;134 continue;74 int ret = 0; 75 if (mpeg4p2_ctx) { 76 // Setup is needed 77 if (!mpeg4p2_ctx->ctx) { 78 ret = av_bsf_alloc(mpeg4p2_ctx->bsf, &mpeg4p2_ctx->ctx); 79 if (ret == 0) { 80 AVStream *in = track->stream; 81 ret = avcodec_parameters_copy(mpeg4p2_ctx->ctx->par_in, in->codecpar); 82 if (ret == 0) { 83 mpeg4p2_ctx->ctx->time_base_in = in->time_base; 84 ret = av_bsf_init(mpeg4p2_ctx->ctx); 85 } 86 } 135 87 } 136 pos += 4; 137 switch ((data[pos] & 0xC0) >> 6) 138 { 139 case 0: // I-Frame 140 case 1: // P-Frame 141 if (!mpeg4p2_ctx->first_ip_frame_written) 142 { 143 mpeg4p2_ctx->first_ip_frame_written = 1; 144 pkt->pts = pkt->dts + mpeg4p2_ctx->packet_duration; 145 ffmpeg_printf(100, "Writing first I/P packet\n"); 146 mpeg4p2_write(ctx, track, cAVIdx, pts_current, pts_latest, pkt); 88 89 if (ret == 0) { 90 ret = av_bsf_send_packet(mpeg4p2_ctx->ctx, pkt); 91 if (ret == 0) { 92 while ((ret = av_bsf_receive_packet(mpeg4p2_ctx->ctx, pkt)) == 0) { 93 mpeg4p2_write(ctx, mpeg4p2_ctx, track, avContextTab[cAVIdx]->start_time, pts_current, pts_latest, pkt); 94 } 95 96 if (ret == AVERROR(EAGAIN)) { 147 97 return 0; 148 98 } 149 else if (!mpeg4p2_ctx->second_ip_frame) 150 {151 set_packet(&mpeg4p2_ctx->second_ip_frame, pkt);152 return 0;99 100 if (ret < 0) { 101 ffmpeg_err("av_bsf_receive_packet failed error 0x%x\n", ret); 102 mpeg4p2_context_reset(mpeg4p2_ctx); 153 103 } 154 else 155 { 156 if (!mpeg4p2_ctx->b_frames_count) 157 { 158 mpeg4p2_ctx->second_ip_frame->pts = mpeg4p2_ctx->second_ip_frame->dts + mpeg4p2_ctx->packet_duration; 159 ffmpeg_printf(100,"Writing second I/P packet(1)\n"); 160 mpeg4p2_write(ctx, track, cAVIdx, pts_current, pts_latest, mpeg4p2_ctx->second_ip_frame); 161 set_packet(&mpeg4p2_ctx->second_ip_frame, pkt); 162 return 0; 163 } 164 else 165 { 166 mpeg4p2_ctx->second_ip_frame->pts = mpeg4p2_ctx->b_frames[mpeg4p2_ctx->b_frames_count -1]->dts + mpeg4p2_ctx->packet_duration; 167 mpeg4p2_ctx->b_frames[0]->pts = mpeg4p2_ctx->second_ip_frame->dts + mpeg4p2_ctx->packet_duration; 168 int i; 169 for (i =1; i < mpeg4p2_ctx->b_frames_count; i++) 170 { 171 mpeg4p2_ctx->b_frames[i]->pts = mpeg4p2_ctx->b_frames[i-1]->dts + mpeg4p2_ctx->packet_duration; 172 } 173 ffmpeg_printf(100, "Writing second I/P packet(2)\n"); 174 mpeg4p2_write(ctx, track, cAVIdx, pts_current, pts_latest, mpeg4p2_ctx->second_ip_frame); 175 set_packet(&mpeg4p2_ctx->second_ip_frame, pkt); 176 for (i =0; i< mpeg4p2_ctx->b_frames_count; i++) 177 { 178 ffmpeg_printf(100, "Writing B-frame[%d]\n", i); 179 mpeg4p2_write(ctx, track, cAVIdx, pts_current, pts_latest, mpeg4p2_ctx->b_frames[i]); 180 } 181 mpeg4p2_ctx->b_frames_count = 0; 182 return 0; 183 } 184 } 185 break; 186 case 3: // S-Frame 187 break; 188 case 2: // B-Frame 189 if (!mpeg4p2_ctx->second_ip_frame) 190 { 191 ffmpeg_err("Cannot predict B-Frame without surrounding I/P-Frames, dropping..."); 192 return 0; 193 } 194 if (mpeg4p2_ctx->b_frames_count == MPEG4P2_MAX_B_FRAMES_COUNT) 195 { 196 ffmpeg_err("Oops max B-Frames count = %d, reached", MPEG4P2_MAX_B_FRAMES_COUNT); 197 // not recoverable, to fix just increase MPEG4P2_MAX_B_FRAMES_COUNT 198 return -1; 199 } 200 else 201 { 202 ffmpeg_printf(100, "Storing B-Frame\n"); 203 set_packet(&mpeg4p2_ctx->b_frames[mpeg4p2_ctx->b_frames_count++], pkt); 204 return 0; 205 } 206 case 4: 207 default: 208 break; 104 } 105 } else { 106 ffmpeg_err("bsf setup failed error 0x%x\n", ret); 209 107 } 108 109 } else { 110 ret = -1; 210 111 } 211 return 0;112 return ret; 212 113 } 213 114 115 static void mpeg4p2_context_close(Mpeg4P2Context *context) 116 { 117 if (context) { 118 mpeg4p2_context_reset(context); 119 free(context); 120 return; 121 } 122 } 123 -
titan/libeplayer3/container/wrapped_ffmpeg.c
r43806 r44958 143 143 if (!avCodecCtx) 144 144 { 145 f printf(stderr,"context3 alloc for stream %d failed\n", (int)stream->id);145 ffmpeg_err("context3 alloc for stream %d failed\n", (int)stream->id); 146 146 return NULL; 147 147 } … … 149 149 if (avcodec_parameters_to_context(avCodecCtx, stream->codecpar) < 0) 150 150 { 151 f printf(stderr,"parameters to context for stream %d failed\n", (int)stream->id);151 ffmpeg_err("parameters to context for stream %d failed\n", (int)stream->id); 152 152 avcodec_free_context(&avCodecCtx); 153 153 return NULL; … … 159 159 #endif 160 160 store_avcodec_context(avCodecCtx, cAVIdx, stream->id); 161 161 162 162 return avCodecCtx; 163 163 } … … 188 188 } 189 189 } 190 #endif 191 } 190 #endif 191 } 192 193 static void wrapped_register_all(void) 194 { 195 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) 196 avcodec_register_all(); 197 av_register_all(); 198 #endif 199 } 200 201 static int64_t wrapped_frame_get_best_effort_timestamp(const AVFrame *frame) 202 { 203 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) 204 return av_frame_get_best_effort_timestamp(frame); 205 #else 206 return frame->best_effort_timestamp; 207 #endif 208 } 209 210 -
titan/libeplayer3/external/ffmpeg/mpeg4audio.h
r40322 r44958 107 107 108 108 int avpriv_copy_pce_data(PutBitContext *pb, GetBitContext *gb); 109 uint8_t get_chan_config(int channels); 109 110 110 111 #endif /* AVCODEC_MPEG4AUDIO_H */ -
titan/libeplayer3/external/ffmpeg/src/latmenc.c
r40322 r44958 27 27 #include <ffmpeg/mpeg4audio.h> 28 28 #include <ffmpeg/latmenc.h> 29 #include "debug.h" 29 30 30 31 /* ***************************** */ 31 32 /* Makros/Constants */ 32 33 /* ***************************** */ 33 //#define LATMENC_SILENT34 35 #ifndef LATMENC_SILENT36 #define latmenc_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)37 #else38 #define latmenc_err(fmt, x...)39 #endif40 41 34 42 35 int latmenc_decode_extradata(LATMContext *ctx, uint8_t *buf, int size) -
titan/libeplayer3/external/ffmpeg/src/mpeg4audio.c
r40322 r44958 77 77 return *index == 0x0f ? get_bits(gb, 24) : 78 78 avpriv_mpeg4audio_sample_rates[*index]; 79 } 80 81 uint8_t get_chan_config(int channels) 82 { 83 uint8_t chan_config = 0; 84 int i; 85 for (i=0; i<FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) { 86 if (channels == ff_mpeg4audio_channels[i]) { 87 chan_config = i; 88 break; 89 } 90 } 91 return chan_config; 79 92 } 80 93 -
titan/libeplayer3/external/flv2mpeg4/src/bitwriter.h
r40322 r44958 121 121 break; 122 122 default: 123 // fprintf(stderr, "flash_bw error!(%d)\n", p->bitoffset);124 123 break; 125 124 } -
titan/libeplayer3/external/flv2mpeg4/src/flvdecoder.c
r40322 r44958 465 465 if (get_bits(p, 17) != 1) 466 466 { 467 fprintf(stderr, "start code error\n");468 467 return -1; 469 468 } … … 472 471 if (tmp !=0 && tmp != 1) 473 472 { 474 fprintf(stderr, "picture format error\n");475 473 return -1; 476 474 } … … 479 477 picture->frame_number = get_bits(p, 8); 480 478 481 // printf("picture_format: %d\n", tmp);482 // printf("picture_number: %d\n", get_bits(p, 8));483 484 479 tmp = get_bits(p, 3); 485 480 switch (tmp) … … 499 494 case 6: width = 160, height = 120; break; 500 495 default: 501 fprintf(stderr, "size error\n");502 496 return -1; 503 497 } -
titan/libeplayer3/include/bcm_ioctls.h
r40322 r44958 52 52 STREAMTYPE_DIVX4 = 14, 53 53 STREAMTYPE_DIVX5 = 15, 54 STREAMTYPE_VB6 = 18, 54 STREAMTYPE_VB6 = 18, /* 17 is also valid for ZGEMMA STBs*/ 55 55 STREAMTYPE_SPARK = 21, 56 STREAMTYPE_MJPEG = 30, 57 STREAMTYPE_RV30 = 31, /* rv30: RealVideo 8, suspected to based largely on an early draft of H.264 (included with RealPlayer 8)*/ 58 STREAMTYPE_RV40 = 32, /* RealVideo 9, RealVideo 10*/ 59 STREAMTYPE_AVS2 = 40, 56 60 } video_stream_type_t; 57 58 59 61 60 62 typedef enum { … … 73 75 AUDIOTYPE_AC3_PLUS = 0x22, 74 76 AUDIOTYPE_AMR = 0x23, 75 AUDIOTYPE_RAW = 0xf 77 AUDIOTYPE_OPUS = 0x24, 78 AUDIOTYPE_VORBIS = 0x25, 79 AUDIOTYPE_RAW = 0x30 76 80 } audio_stream_type_t; 77 81 -
titan/libeplayer3/include/common.h
r42431 r44958 10 10 #include <pthread.h> 11 11 12 typedef char PlayFilesTab_t[2];13 14 12 typedef struct PlayFiles_t 15 13 { 16 14 char *szFirstFile; 17 15 char *szSecondFile; 16 char *szFirstMoovAtomFile; 17 char *szSecondMoovAtomFile; 18 uint64_t iFirstFileSize; 19 uint64_t iSecondFileSize; 20 uint64_t iFirstMoovAtomOffset; 21 uint64_t iSecondMoovAtomOffset; 18 22 } PlayFiles_t; 19 23 … … 25 29 ManagerHandler_t *manager; 26 30 } Context_t; 31 // obi 32 char* subtext; 33 // obi 34 int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initial); 27 35 28 char* subtext; 36 const char* GetGraphicSubPath(); 37 int32_t GetGraphicWindowWidth(); 38 int32_t GetGraphicWindowHeight(); 29 39 30 int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initial); 40 void E2iSendMsg(const char * format, ...); 41 void E2iStartMsg(void); 42 void E2iEndMsg(void); 43 31 44 #endif -
titan/libeplayer3/include/container.h
r41347 r44958 25 25 CONTAINER_GET_BUFFER_STATUS, 26 26 CONTAINER_STOP_BUFFER, 27 //obi 27 28 CONTAINER_GET_SUBTEXT 29 //obi 28 30 } ContainerCmd_t; 29 31 -
titan/libeplayer3/include/manager.h
r42431 r44958 18 18 MANAGER_UPDATED_TRACK_INFO, 19 19 MANAGER_REGISTER_UPDATED_TRACK_INFO, 20 MANAGER_REF_LIST, 21 MANAGER_REF_LIST_SIZE, 20 22 } ManagerCmd_t; 21 23 … … 28 30 char * Name; 29 31 char * Encoding; 32 // obi 30 33 char * File; 34 // obi 31 35 int32_t Id; 32 36 int32_t AVIdx; -
titan/libeplayer3/include/misc.h
r40322 r44958 1 #ifndef misc_1232 #define misc_1231 #ifndef _exteplayer3_misc_ 2 #define _exteplayer3_misc_ 3 3 4 4 #include <dirent.h> … … 21 21 } BitPacker_t; 22 22 23 typedef enum { 24 STB_UNKNOWN, 25 STB_DREAMBOX, 26 STB_VUPLUS, 27 STB_HISILICON, 28 STB_OTHER=999, 29 } stb_type_t; 30 23 31 /* ***************************** */ 24 32 /* Makros/Constants */ 25 33 /* ***************************** */ 26 27 34 #define INVALID_PTS_VALUE 0x200000000ull 28 35 … … 30 37 /* Prototypes */ 31 38 /* ***************************** */ 32 33 39 void PutBits(BitPacker_t * ld, uint32_t code, uint32_t length); 34 40 void FlushBits(BitPacker_t * ld); 35 41 int8_t PlaybackDieNow(int8_t val); 42 stb_type_t GetSTBType(); 36 43 37 44 /* ***************************** */ … … 52 59 } 53 60 54 /* the function returns the base name */55 static inline char * basename(char * name)56 {57 int i = 0;58 int pos = 0;59 60 while(name[i] != 0)61 {62 if(name[i] == '/')63 pos = i;64 i++;65 }66 67 if(name[pos] == '/')68 pos++;69 70 return name + pos;71 }72 73 /* the function returns the directry name */74 static inline char * dirname(char * name)75 {76 static char path[100];77 uint32_t i = 0;78 int32_t pos = 0;79 80 while((name[i] != 0) && (i < sizeof(path)))81 {82 if(name[i] == '/')83 {84 pos = i;85 }86 path[i] = name[i];87 i++;88 }89 90 path[i] = 0;91 path[pos] = 0;92 93 return path;94 }95 96 static inline int32_t IsDreambox()97 {98 struct stat buffer;99 return (stat("/proc/stb/tpm/0/serial", &buffer) == 0);100 }101 102 61 static inline uint32_t ReadUint32(uint8_t *buffer) 103 62 { … … 116 75 } 117 76 118 #endif 77 #endif // _exteplayer3_misc_ -
titan/libeplayer3/include/output.h
r42431 r44958 27 27 OUTPUT_GET_FRAME_COUNT, 28 28 OUTPUT_GET_PROGRESSIVE, 29 OUTPUT_SET_BUFFER_SIZE, 30 OUTPUT_GET_BUFFER_SIZE, 29 31 } OutputCmd_t; 30 32 … … 53 55 typedef struct 54 56 { 55 uint32_t trackId; 56 uint8_t *data; 57 uint32_t len; 58 59 int64_t pts; 60 int64_t durationMS; // duration in miliseconds 61 62 char *type; 57 uint32_t trackId; 58 uint8_t *data; 59 uint32_t len; 60 61 uint8_t *extradata; 62 uint32_t extralen; 63 64 int64_t pts; 65 int64_t dts; 66 int64_t durationMS; // duration in miliseconds 67 68 uint32_t width; 69 uint32_t height; 70 71 char *type; 63 72 } SubtitleOut_t; 64 73 … … 68 77 char * Name; 69 78 int32_t (* Command) (/*Context_t*/void *, OutputCmd_t, void *); 70 int32_t (* Write) (/*Context_t*/void *, void * privateData);79 int32_t (* Write) (/*Context_t*/void *, void *); 71 80 char ** Capabilities; 72 81 -
titan/libeplayer3/include/playback.h
r42431 r44958 3 3 #include <sys/types.h> 4 4 #include <stdint.h> 5 #include <stdbool.h> 6 7 typedef void( * PlaybackDieNowCallback )(); 8 bool PlaybackDieNowRegisterCallback(PlaybackDieNowCallback callback); 5 9 6 10 typedef 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; … … 37 41 uint8_t isLoopMode; 38 42 uint8_t isTSLiveMode; 43 44 void *stamp; 39 45 } PlaybackHandler_t; 40 46 -
titan/libeplayer3/include/writer.h
r42431 r44958 5 5 #include <stdio.h> 6 6 #include <stdint.h> 7 #include "common.h" 7 8 8 9 typedef enum { eNone, eAudio, eVideo} eWriterType_t; 10 typedef ssize_t (* WriteV_t) (int, const struct iovec *, int); 9 11 10 12 typedef struct { … … 22 24 unsigned char Version; 23 25 unsigned int InfoFlags; 26 WriteV_t WriteV; 24 27 } WriterAVCallData_t; 25 26 27 28 28 29 typedef struct WriterCaps_s { … … 57 58 extern Writer_t WriterAudioWMAPRO; 58 59 extern Writer_t WriterAudioFLAC; 60 extern Writer_t WriterAudioAMR; 59 61 extern Writer_t WriterAudioVORBIS; 60 extern Writer_t WriterAudio AMR;62 extern Writer_t WriterAudioOPUS; 61 63 62 64 extern Writer_t WriterVideoMPEG1; … … 77 79 extern Writer_t WriterVideoVP8; 78 80 extern Writer_t WriterVideoVP9; 79 extern Writer_t WriterVideo SPARK;81 extern Writer_t WriterVideoMJPEG; 80 82 extern Writer_t WriterFramebuffer; 81 83 extern Writer_t WriterPipe; 84 extern Writer_t WriterVideoRV30; 85 extern Writer_t WriterVideoRV40; 86 extern Writer_t WriterVideoAVS2; 82 87 83 88 Writer_t* getWriter(char* encoding); … … 85 90 Writer_t* getDefaultVideoWriter(); 86 91 Writer_t* getDefaultAudioWriter(); 87 ssize_t write_with_retry(int fd, const void *buf, size_t size); 88 ssize_t writev_with_retry(int fd, const struct iovec *iov, size_t ic); 92 ssize_t write_with_retry(int fd, const void *buf, int size); 93 ssize_t writev_with_retry(int fd, const struct iovec *iov, int ic); 94 95 ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, void *pDVBMtx, const void *buf, int size); 96 void FlushPipe(int pipefd); 97 98 ssize_t WriteExt(WriteV_t _call, int fd, void *data, size_t size); 99 100 // Subtitles 101 102 typedef enum { 103 SUBTITLE_CODEC_ID_UNKNOWN, 104 SUBTITLE_CODEC_ID_SUBRIP, 105 SUBTITLE_CODEC_ID_ASS, 106 SUBTITLE_CODEC_ID_WEBVTT, 107 SUBTITLE_CODEC_ID_PGS, 108 SUBTITLE_CODEC_ID_DVB, 109 SUBTITLE_CODEC_ID_XSUB 110 } SubtitleCodecId_t; 111 112 typedef struct { 113 SubtitleCodecId_t codecId; 114 uint32_t trackId; 115 uint8_t *data; 116 uint32_t len; 117 int64_t pts; 118 int64_t dts; 119 uint8_t *private_data; 120 uint32_t private_size; 121 122 int64_t durationMS; // duration in miliseconds 123 124 uint32_t width; 125 uint32_t height; 126 } WriterSubCallData_t; 127 128 typedef struct SubWriter_s { 129 int32_t (* open) (SubtitleCodecId_t codecId, uint8_t *extradata, int extradata_size); 130 int32_t (* close) (); 131 int32_t (* reset) (); 132 int32_t (* write) (WriterSubCallData_t *); 133 } SubWriter_t; 134 135 extern SubWriter_t WriterSubPGS; 136 89 137 #endif -
titan/libeplayer3/main/exteplayer.c
r42431 r44958 24 24 #include <sched.h> 25 25 #include <signal.h> 26 #include <inttypes.h> 27 #include <stdarg.h> 26 28 27 29 #include <sys/ioctl.h> … … 41 43 #include "misc.h" 42 44 45 #include "debug.h" 46 43 47 #define DUMP_BOOL(x) 0 == x ? "false" : "true" 44 48 #define IPTV_MAX_FILE_PATH 1024 … … 52 56 extern void eac3_software_decoder_set(const int32_t val); 53 57 extern void mp3_software_decoder_set(const int32_t val); 58 extern void amr_software_decoder_set(const int32_t val); 59 extern void vorbis_software_decoder_set(const int32_t val); 60 extern void opus_software_decoder_set(const int32_t val); 61 54 62 extern void rtmp_proto_impl_set(const int32_t val); 55 63 extern void flv2mpeg4_converter_set(const int32_t val); … … 85 93 } 86 94 87 static int g_pfd[2] = {-1, -1}; /* Used to wake terminate thread */95 static int g_pfd[2] = {-1, -1}; /* Used to wake terminate thread and kbhit */ 88 96 static int isPlaybackStarted = 0; 89 97 static pthread_mutex_t playbackStartMtx; 90 98 99 static int32_t g_windows_width = 1280; 100 static int32_t g_windows_height = 720; 101 static char *g_graphic_sub_path; 102 103 const char* GetGraphicSubPath() 104 { 105 return g_graphic_sub_path; 106 } 107 108 int32_t GetGraphicWindowWidth() 109 { 110 return g_windows_width; 111 } 112 113 int32_t GetGraphicWindowHeight() 114 { 115 return g_windows_height; 116 } 117 118 void E2iSendMsg(const char *format, ...) 119 { 120 va_list args; 121 va_start(args, format); 122 vfprintf(stderr, format, args); 123 va_end(args); 124 } 125 126 void E2iStartMsg(void) 127 { 128 flockfile(stderr); 129 } 130 131 void E2iEndMsg(void) 132 { 133 funlockfile(stderr); 134 } 135 136 137 static void TerminateWakeUp() 138 { 139 int ret = write(g_pfd[1], "x", 1); 140 if (ret != 1) { 141 printf("TerminateWakeUp write return %d\n", ret); 142 } 143 } 144 91 145 static void *TermThreadFun(void *arg) 92 146 { 93 const char *socket_path = "/tmp/ iptvplayer_extplayer_term_fd";147 const char *socket_path = "/tmp/.exteplayerterm.socket"; 94 148 struct sockaddr_un addr; 95 149 int fd = -1; … … 136 190 if (FD_ISSET(fd, &readfds)) 137 191 { 138 /*139 if ( (cl = accept(fd, NULL, NULL)) == -1)140 {141 perror("TermThreadFun accept error");142 goto finish;143 }144 */145 146 192 pthread_mutex_lock(&playbackStartMtx); 147 193 PlaybackDieNow(1); … … 184 230 { 185 231 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)) 232 fd_set readfds; 233 234 tv.tv_sec = 1; 235 tv.tv_usec = 0; 236 237 FD_ZERO(&readfds); 238 FD_SET(0,&readfds); 239 FD_SET(g_pfd[0], &readfds); 240 241 if(-1 == select(g_pfd[0] + 1, &readfds, NULL, NULL, &tv)) 195 242 { 196 243 return 0; 197 244 } 198 245 199 if(FD_ISSET(0, &read_fd))246 if(FD_ISSET(0, &readfds)) 200 247 { 201 248 return 1; … … 256 303 { 257 304 int i = 0; 258 fprintf(stderr, "{\"%c_%c\": [", argvBuff[0], argvBuff[1]); 305 E2iStartMsg(); 306 E2iSendMsg("{\"%c_%c\": [", argvBuff[0], argvBuff[1]); 259 307 for (i = 0; TrackList[i].Id >= 0; ++i) 260 308 { 261 309 if(0 < i) 262 310 { 263 fprintf(stderr,", ");311 E2iSendMsg(", "); 264 312 } 265 fprintf(stderr,"{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}", TrackList[i].Id , TrackList[i].Encoding, TrackList[i].Name);313 E2iSendMsg("{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}", TrackList[i].Id , TrackList[i].Encoding, TrackList[i].Name); 266 314 free(TrackList[i].Encoding); 267 315 free(TrackList[i].Name); 268 316 } 269 fprintf(stderr, "]}\n"); 317 E2iSendMsg("]}\n"); 318 E2iEndMsg(); 270 319 free(TrackList); 271 320 } … … 273 322 { 274 323 // not tracks 275 fprintf(stderr,"{\"%c_%c\": []}\n", argvBuff[0], argvBuff[1]);324 E2iSendMsg("{\"%c_%c\": []}\n", argvBuff[0], argvBuff[1]); 276 325 } 277 326 break; … … 286 335 if ('a' == argvBuff[0] || 's' == argvBuff[0]) 287 336 { 288 fprintf(stderr,"{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}}\n", argvBuff[0], argvBuff[1], track->Id , track->Encoding, track->Name);337 E2iSendMsg("{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}}\n", argvBuff[0], argvBuff[1], track->Id , track->Encoding, track->Name); 289 338 } 290 339 else // video 291 340 { 292 fprintf(stderr,"{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\",\"w\":%d,\"h\":%d,\"f\":%u,\"p\":%d,\"an\":%d,\"ad\":%d}}\n", \341 E2iSendMsg("{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\",\"w\":%d,\"h\":%d,\"f\":%u,\"p\":%d,\"an\":%d,\"ad\":%d}}\n", \ 293 342 argvBuff[0], argvBuff[1], track->Id , track->Encoding, track->Name, track->width, track->height, track->frame_rate, track->progressive, track->aspect_ratio_num, track->aspect_ratio_den); 294 343 } … … 302 351 if ('a' == argvBuff[0] || 's' == argvBuff[0]) 303 352 { 304 fprintf(stderr,"{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}}\n", argvBuff[0], argvBuff[1], -1, "", "");353 E2iSendMsg("{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}}\n", argvBuff[0], argvBuff[1], -1, "", ""); 305 354 } 306 355 else // video 307 356 { 308 fprintf(stderr,"{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\",\"w\":%d,\"h\":%d,\"f\":%u,\"p\":%d}}\n", argvBuff[0], argvBuff[1], -1, "", "", -1, -1, 0, -1);357 E2iSendMsg("{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\",\"w\":%d,\"h\":%d,\"f\":%u,\"p\":%d}}\n", argvBuff[0], argvBuff[1], -1, "", "", -1, -1, 0, -1); 309 358 } 310 359 } … … 354 403 { 355 404 commandRetVal = g_player->playback->Command(g_player, playbackSwitchCmd, (void*)&id); 356 fprintf(stderr,"{\"%c_%c\":{\"id\":%d,\"sts\":%d}}\n", argvBuff[0], 's', id, commandRetVal);405 E2iSendMsg("{\"%c_%c\":{\"id\":%d,\"sts\":%d}}\n", argvBuff[0], 's', id, commandRetVal); 357 406 } 358 407 } … … 369 418 } 370 419 371 static int ParseParams(int argc,char* argv[], char *file, char *audioFile, int *pAudioTrackIdx, int *subtitleTrackIdx)420 static int ParseParams(int argc,char* argv[], PlayFiles_t *playbackFiles, int *pAudioTrackIdx, int *subtitleTrackIdx, uint32_t *linuxDvbBufferSizeMB) 372 421 { 373 422 int ret = 0; … … 376 425 int aopt = 0, bopt = 0; 377 426 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)427 while ( (c = getopt(argc, argv, "G:W:H:A:V:U:we3dlsrimva:n:x:u:c:h:o:p:P:t:9:0:1:4:f:b:F:S:O:")) != -1) 379 428 { 380 429 switch (c) 381 430 { 431 case 'G': 432 g_graphic_sub_path = optarg; 433 case 'W': 434 { 435 int val = atoi(optarg); 436 if (val) g_windows_width = val; 437 break; 438 } 439 case 'H': 440 { 441 int val = atoi(optarg); 442 if (val) g_windows_height = val; 443 break; 444 } 382 445 case 'a': 383 446 { … … 392 455 eac3_software_decoder_set(1); 393 456 break; 457 case 'A': 458 printf("Software decoder will be used for AMR codec\n"); 459 amr_software_decoder_set(atoi(optarg)); 460 break; 461 case 'V': 462 printf("Software decoder will be used for VORBIS codec\n"); 463 vorbis_software_decoder_set(atoi(optarg)); 464 break; 465 case 'U': 466 printf("Software decoder will be used for OPUS codec\n"); 467 vorbis_software_decoder_set(atoi(optarg)); 468 break; 394 469 case '3': 395 470 printf("Software decoder will be used for AC3 codec\n"); … … 437 512 break; 438 513 case 'x': 439 strncpy(audioFile, optarg, IPTV_MAX_FILE_PATH-1); 440 map_inter_file_path(audioFile); 514 if (optarg[0] != '\0') 515 { 516 playbackFiles->szSecondFile = malloc(IPTV_MAX_FILE_PATH); 517 playbackFiles->szSecondFile[0] = '\0'; 518 strncpy(playbackFiles->szSecondFile, optarg, IPTV_MAX_FILE_PATH-1); 519 playbackFiles->szSecondFile[IPTV_MAX_FILE_PATH] = '\0'; 520 map_inter_file_path(playbackFiles->szSecondFile); 521 } 441 522 break; 442 523 case 'h': … … 486 567 break; 487 568 } 569 case 'b': 570 *linuxDvbBufferSizeMB = 1024 * 1024 * atoi(optarg); 571 break; 572 case 'S': 573 playbackFiles->iFirstFileSize = (uint64_t) strtoull(optarg, (char **)NULL, 10); 574 break; 575 case 'O': 576 playbackFiles->iFirstMoovAtomOffset = (uint64_t) strtoull(optarg, (char **)NULL, 10); 577 break; 578 case 'F': 579 if (optarg[0] != '\0') 580 { 581 playbackFiles->szFirstMoovAtomFile = malloc(IPTV_MAX_FILE_PATH); 582 playbackFiles->szFirstMoovAtomFile[0] = '\0'; 583 strncpy(playbackFiles->szFirstMoovAtomFile, optarg, IPTV_MAX_FILE_PATH-1); 584 playbackFiles->szFirstMoovAtomFile[IPTV_MAX_FILE_PATH] = '\0'; 585 map_inter_file_path(playbackFiles->szFirstMoovAtomFile); 586 } 587 break; 488 588 default: 489 589 printf ("?? getopt returned character code 0%o ??\n", c); … … 495 595 { 496 596 ret = 0; 497 597 playbackFiles->szFirstFile = malloc(IPTV_MAX_FILE_PATH); 598 playbackFiles->szFirstFile[0] = '\0'; 498 599 if(NULL == strstr(argv[optind], "://")) 499 600 { 500 strcpy(file, "file://"); 501 } 502 strcat(file, argv[optind]); 503 map_inter_file_path(file); 504 printf("file: [%s]\n", file); 601 strcpy(playbackFiles->szFirstFile, "file://"); 602 } 603 strcat(playbackFiles->szFirstFile, argv[optind]); 604 playbackFiles->szFirstFile[IPTV_MAX_FILE_PATH] = '\0'; 605 map_inter_file_path(playbackFiles->szFirstFile); 606 printf("file: [%s]\n", playbackFiles->szFirstFile); 505 607 ++optind; 506 608 } … … 516 618 pthread_t termThread; 517 619 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));523 620 524 621 int audioTrackIdx = -1; 525 622 int subtitleTrackIdx = -1; 623 624 uint32_t linuxDvbBufferSizeMB = 0; 526 625 527 626 char argvBuff[256]; 528 627 memset(argvBuff, '\0', sizeof(argvBuff)); 529 628 int commandRetVal = -1; 629 530 630 /* 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)) 631 E2iSendMsg("{\"EPLAYER3_EXTENDED\":{\"version\":%d}}\n", 68); 632 633 PlayFiles_t playbackFiles; 634 memset(&playbackFiles, 0x00, sizeof(playbackFiles)); 635 636 if (0 != ParseParams(argc, argv, &playbackFiles, &audioTrackIdx, &subtitleTrackIdx, &linuxDvbBufferSizeMB)) 534 637 { 535 638 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"); 639 printf("[-b size] Linux DVB output buffer size in MB\n"); 536 640 printf("[-a 0|1|2|3] AAC software decoding - 1 bit - AAC ADTS, 2 - bit AAC LATM\n"); 537 641 printf("[-e] EAC3 software decoding\n"); … … 539 643 printf("[-d] DTS software decoding\n"); 540 644 printf("[-m] MP3 software decoding\n"); 541 printf("[-w] WMA1, WMA2, WMA/PRO software decoding\n"); 645 printf("[-A 0|1] disable|enable AMR software decoding\n"); 646 printf("[-V 0|1] disable|enable VORBIS software decoding\n"); 647 printf("[-U 0|1] disable|enable AMR software decoding\n"); 648 printf("[-w] WMA2, WMA/PRO software decoding\n"); 542 649 printf("[-l] software decoder use LPCM for injection (otherwise wav PCM will be used)\n"); 543 650 printf("[-s] software decoding as stereo [downmix]\n"); … … 547 654 printf("[-i] play in infinity loop\n"); 548 655 printf("[-v] switch to live TS stream mode\n"); 549 printf("[-n 0|1|2] rtmp force protocol implementation auto(0) native/ffmpeg(1) or librtmp(2)\n"); 656 printf("[-n 0|1|2] rtmp force protocol implementation auto(0) native/ffmpeg(1) or librtmp(2)\n"); 550 657 printf("[-o 0|1] set progressive download\n"); 551 658 printf("[-p value] nice value\n"); … … 560 667 printf("[-1 idx] audio MPEG-DASH representation index\n"); 561 668 printf("[-f ffopt=ffval] any other ffmpeg option\n"); 562 669 printf("[-F path to additional file with moov atom data (used for mp4 playback in progressive download mode)\n"); 670 printf("[-O moov atom offset in the original file (used for mp4 playback in progressive download mode)\n"); 671 printf("[-S remote file size (used for mp4 playback in progressive download mode)\n"); 672 printf("[-G path (directory where graphic subtitles frames will be saved)\n"); 673 printf("[-W osd window width (width of the window used to scale graphic subtitle frame)\n"); 674 printf("[-H osd window height (height of the window used to scale graphic subtitle frame)\n"); 563 675 exit(1); 564 676 } … … 599 711 isTermThreadStarted = 1; 600 712 } while(0); 601 713 602 714 g_player->playback = &PlaybackHandler; 603 715 g_player->output = &OutputHandler; … … 609 721 610 722 SetBuffering(); 611 723 612 724 //Registrating output devices 613 725 g_player->output->Command(g_player, OUTPUT_ADD, "audio"); 614 726 g_player->output->Command(g_player, OUTPUT_ADD, "video"); 615 727 g_player->output->Command(g_player, OUTPUT_ADD, "subtitle"); 616 728 729 //Set LINUX DVB additional write buffer size 730 if (linuxDvbBufferSizeMB) 731 g_player->output->Command(g_player, OUTPUT_SET_BUFFER_SIZE, &linuxDvbBufferSizeMB); 732 617 733 g_player->manager->video->Command(g_player, MANAGER_REGISTER_UPDATED_TRACK_INFO, UpdateVideoTrack); 618 if (strncmp( file, "rtmp", 4) && strncmp(file, "ffrtmp", 4))734 if (strncmp(playbackFiles.szFirstFile, "rtmp", 4) && strncmp(playbackFiles.szFirstFile, "ffrtmp", 4)) 619 735 { 620 736 g_player->playback->noprobe = 1; 621 737 } 622 738 623 PlayFiles_t playbackFiles = {file, NULL};624 if('\0' != audioFile[0])625 {626 playbackFiles.szSecondFile = audioFile;627 }628 629 739 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);740 E2iSendMsg("{\"PLAYBACK_OPEN\":{\"OutputName\":\"%s\", \"file\":\"%s\", \"sts\":%d}}\n", g_player->output->Name, playbackFiles.szFirstFile, commandRetVal); 631 741 if(commandRetVal < 0) 632 742 { … … 644 754 645 755 commandRetVal = g_player->output->Command(g_player, OUTPUT_OPEN, NULL); 646 fprintf(stderr,"{\"OUTPUT_OPEN\":{\"sts\":%d}}\n", commandRetVal);756 E2iSendMsg("{\"OUTPUT_OPEN\":{\"sts\":%d}}\n", commandRetVal); 647 757 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_PLAY, NULL); 648 fprintf(stderr,"{\"PLAYBACK_PLAY\":{\"sts\":%d}}\n", commandRetVal);758 E2iSendMsg("{\"PLAYBACK_PLAY\":{\"sts\":%d}}\n", commandRetVal); 649 759 650 760 if (g_player->playback->isPlaying) 651 761 { 762 PlaybackDieNowRegisterCallback(TerminateWakeUp); 763 652 764 HandleTracks(g_player->manager->video, (PlaybackCmd_t)-1, "vc"); 653 765 HandleTracks(g_player->manager->audio, (PlaybackCmd_t)-1, "al"); … … 660 772 HandleTracks(g_player->manager->audio, (PlaybackCmd_t)-1, "ac"); 661 773 774 662 775 HandleTracks(g_player->manager->subtitle, (PlaybackCmd_t)-1, "sl"); 663 776 if (subtitleTrackIdx >= 0) … … 670 783 } 671 784 672 while(g_player->playback->isPlaying )785 while(g_player->playback->isPlaying && 0 == PlaybackDieNow(0)) 673 786 { 674 787 /* we made fgets non blocking */ … … 705 818 { 706 819 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_STOP, NULL); 707 fprintf(stderr,"{\"PLAYBACK_STOP\":{\"sts\":%d}}\n", commandRetVal);820 E2iSendMsg("{\"PLAYBACK_STOP\":{\"sts\":%d}}\n", commandRetVal); 708 821 break; 709 822 } … … 711 824 { 712 825 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_CONTINUE, NULL); 713 fprintf(stderr,"{\"PLAYBACK_CONTINUE\":{\"sts\":%d}}\n", commandRetVal);826 E2iSendMsg("{\"PLAYBACK_CONTINUE\":{\"sts\":%d}}\n", commandRetVal); 714 827 break; 715 828 } … … 717 830 { 718 831 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_PAUSE, NULL); 719 fprintf(stderr,"{\"PLAYBACK_PAUSE\":{\"sts\":%d}}\n", commandRetVal);832 E2iSendMsg("{\"PLAYBACK_PAUSE\":{\"sts\":%d}}\n", commandRetVal); 720 833 break; 721 834 } … … 726 839 727 840 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_SLOWMOTION, &speed); 728 fprintf(stderr,"{\"PLAYBACK_SLOWMOTION\":{\"speed\":%d, \"sts\":%d}}\n", speed, commandRetVal);841 E2iSendMsg("{\"PLAYBACK_SLOWMOTION\":{\"speed\":%d, \"sts\":%d}}\n", speed, commandRetVal); 729 842 break; 730 843 } … … 735 848 { 736 849 progressive_playback_set(flags); 737 fprintf(stderr,"{\"PROGRESSIVE_DOWNLOAD\":{\"flags\":%d, \"sts\":0}}\n", flags);850 E2iSendMsg("{\"PROGRESSIVE_DOWNLOAD\":{\"flags\":%d, \"sts\":0}}\n", flags); 738 851 } 739 852 break; … … 745 858 746 859 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_FASTFORWARD, &speed); 747 fprintf(stderr,"{\"PLAYBACK_FASTFORWARD\":{\"speed\":%d, \"sts\":%d}}\n", speed, commandRetVal);860 E2iSendMsg("{\"PLAYBACK_FASTFORWARD\":{\"speed\":%d, \"sts\":%d}}\n", speed, commandRetVal); 748 861 break; 749 862 } … … 754 867 755 868 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_FASTBACKWARD, &speed); 756 fprintf(stderr,"{\"PLAYBACK_FASTBACKWARD\":{\"speed\":%d, \"sts\":%d}}\n", speed, commandRetVal);869 E2iSendMsg("{\"PLAYBACK_FASTBACKWARD\":{\"speed\":%d, \"sts\":%d}}\n", speed, commandRetVal); 757 870 break; 758 871 } … … 769 882 { 770 883 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_LENGTH, (void*)&length); 771 fprintf(stderr, "{\"PLAYBACK_LENGTH\":{\"length\":%lld, \"sts\":%d}}\n", length, commandRetVal);884 E2iSendMsg("{\"PLAYBACK_LENGTH\":{\"length\":%"PRId64", \"sts\":%d}}\n", length, commandRetVal); 772 885 773 886 lengthInt = (int32_t)length; … … 781 894 782 895 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_SEEK_ABS, (void*)&sec); 783 fprintf(stderr, "{\"PLAYBACK_SEEK_ABS\":{\"sec\":%lld, \"sts\":%d}}\n", sec, commandRetVal);896 E2iSendMsg("{\"PLAYBACK_SEEK_ABS\":{\"sec\":%"PRId64", \"sts\":%d}}\n", sec, commandRetVal); 784 897 } 785 898 } … … 802 915 if (0 == commandRetVal) 803 916 { 804 fprintf(stderr, "{\"J\":{\"ms\":%lld}}\n", pts / 90, commandRetVal);917 E2iSendMsg("{\"J\":{\"ms\":%"PRId64"}}\n", pts / 90); 805 918 } 806 919 if(0 == commandRetVal || force) 807 920 { 808 921 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_LENGTH, (void*)&length); 809 fprintf(stderr, "{\"PLAYBACK_LENGTH\":{\"length\":%lld, \"sts\":%d}}\n", length, commandRetVal);922 E2iSendMsg("{\"PLAYBACK_LENGTH\":{\"length\":%"PRId64", \"sts\":%d}}\n", length, commandRetVal); 810 923 811 924 lengthInt = (int32_t)length; … … 831 944 } 832 945 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_SEEK, (void*)&sec); 833 fprintf(stderr, "{\"PLAYBACK_SEEK\":{\"sec\":%lld, \"sts\":%d}}\n", sec, commandRetVal);946 E2iSendMsg("{\"PLAYBACK_SEEK\":{\"sec\":%"PRId64", \"sts\":%d}}\n", sec, commandRetVal); 834 947 } 835 948 break; … … 839 952 int64_t length = 0; 840 953 commandRetVal = g_player->playback->Command(g_player, PLAYBACK_LENGTH, (void*)&length); 841 fprintf(stderr, "{\"PLAYBACK_LENGTH\":{\"length\":%lld, \"sts\":%d}}\n", length, commandRetVal);954 E2iSendMsg("{\"PLAYBACK_LENGTH\":{\"length\":%"PRId64", \"sts\":%d}}\n", length, commandRetVal); 842 955 break; 843 956 } … … 848 961 if (0 == commandRetVal) 849 962 { 850 fprintf(stderr, "{\"J\":{\"ms\":%lld}}\n", pts / 90, commandRetVal); 963 int64_t lastPts = 0; 964 commandRetVal = 1; 965 if (g_player->container && g_player->container->selectedContainer) 966 { 967 commandRetVal = g_player->container->selectedContainer->Command(g_player->container, CONTAINER_LAST_PTS, &lastPts); 968 } 969 970 if (0 == commandRetVal && lastPts != INVALID_PTS_VALUE) 971 { 972 E2iSendMsg("{\"J\":{\"ms\":%"PRId64",\"lms\":%"PRId64"}}\n", pts / 90, lastPts / 90); 973 } 974 else 975 { 976 E2iSendMsg("{\"J\":{\"ms\":%"PRId64"}}\n", pts / 90); 977 } 851 978 } 852 979 break; … … 857 984 if(ptrP) 858 985 { 859 fprintf(stderr,"{\"PLAYBACK_INFO\":{ \"isPlaying\":%s, \"isPaused\":%s, \"isForwarding\":%s, \"isSeeking\":%s, \"isCreationPhase\":%s,", \986 E2iSendMsg("{\"PLAYBACK_INFO\":{ \"isPlaying\":%s, \"isPaused\":%s, \"isForwarding\":%s, \"isSeeking\":%s, \"isCreationPhase\":%s,", \ 860 987 DUMP_BOOL(ptrP->isPlaying), DUMP_BOOL(ptrP->isPaused), DUMP_BOOL(ptrP->isForwarding), DUMP_BOOL(ptrP->isSeeking), DUMP_BOOL(ptrP->isCreationPhase) ); 861 fprintf(stderr,"\"BackWard\":%d, \"SlowMotion\":%d, \"Speed\":%d, \"AVSync\":%d,", ptrP->BackWard, ptrP->SlowMotion, ptrP->Speed, ptrP->AVSync);862 fprintf(stderr," \"isVideo\":%s, \"isAudio\":%s, \"isSubtitle\":%s, \"isDvbSubtitle\":%s, \"isTeletext\":%s, \"mayWriteToFramebuffer\":%s, \"abortRequested\":%s }}\n", \988 E2iSendMsg("\"BackWard\":%d, \"SlowMotion\":%d, \"Speed\":%d, \"AVSync\":%d,", ptrP->BackWard, ptrP->SlowMotion, ptrP->Speed, ptrP->AVSync); 989 E2iSendMsg(" \"isVideo\":%s, \"isAudio\":%s, \"isSubtitle\":%s, \"isDvbSubtitle\":%s, \"isTeletext\":%s, \"mayWriteToFramebuffer\":%s, \"abortRequested\":%s }}\n", \ 863 990 DUMP_BOOL(ptrP->isVideo), DUMP_BOOL(ptrP->isAudio), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(ptrP->abortRequested) ); 864 991 } … … 875 1002 { 876 1003 ptrP->isLoopMode = '1' == argvBuff[1] ? 1 : 0; 877 fprintf(stderr,"{\"N\":{ \"isLoop\":%s }}\n", DUMP_BOOL(ptrP->isLoopMode));1004 E2iSendMsg("{\"N\":{ \"isLoop\":%s }}\n", DUMP_BOOL(ptrP->isLoopMode)); 878 1005 } 879 1006 } … … 905 1032 close(g_pfd[0]); 906 1033 close(g_pfd[1]); 907 908 //printOutputCapabilities(); 909 1034 910 1035 exit(0); 911 1036 } -
titan/libeplayer3/manager/audio.c
r42431 r44958 28 28 #include "manager.h" 29 29 #include "common.h" 30 #include "debug.h" 30 31 31 32 /* ***************************** */ … … 33 34 /* ***************************** */ 34 35 #define TRACKWRAP 20 35 36 //#define SAM_WITH_DEBUG37 #ifdef SAM_WITH_DEBUG38 #define AUDIO_MGR_DEBUG39 #else40 #define AUDIO_MGR_SILENT41 #endif42 43 #ifdef AUDIO_MGR_DEBUG44 45 static short debug_level = 40;46 47 #define audio_mgr_printf(level, fmt, x...) do { \48 if (debug_level >= level) printf("[%s:%s] \n" fmt, __FILE__, __FUNCTION__, ## x); } while (0)49 #else50 #define audio_mgr_printf(level, x...)51 #endif52 53 #ifndef AUDIO_MGR_SILENT54 #define audio_mgr_err(x...) do { printf(x); } while (0)55 #else56 #define audio_mgr_err(x...)57 #endif58 36 59 37 /* Error Constants */ … … 220 198 break; 221 199 } 200 case MANAGER_REF_LIST: 201 { 202 *((Track_t **)argument) = Tracks; 203 break; 204 } 205 case MANAGER_REF_LIST_SIZE: 206 { 207 *((int*)argument) = TrackCount; 208 break; 209 } 210 222 211 case MANAGER_GET: 223 212 { -
titan/libeplayer3/manager/subtitle.c
r40322 r44958 24 24 #include <stdlib.h> 25 25 #include <string.h> 26 #include <assert.h> 26 27 27 28 #include "manager.h" 28 29 #include "common.h" 30 #include "debug.h" 29 31 30 32 /* ***************************** */ 31 33 /* Makros/Constants */ 32 34 /* ***************************** */ 33 #define TRACKWRAP 20 34 35 //#define SAM_WITH_DEBUG 36 #ifdef SAM_WITH_DEBUG 37 #define SUBTITLE_MGR_DEBUG 38 #else 39 #define SUBTITLE_MGR_SILENT 40 #endif 41 42 43 #ifdef SUBTITLE_MGR_DEBUG 44 45 static short debug_level = 10; 46 47 #define subtitle_mgr_printf(level, x...) do { \ 48 if (debug_level >= level) printf(x); } while (0) 49 #else 50 #define subtitle_mgr_printf(level, x...) 51 #endif 52 53 #ifndef SUBTITLE_MGR_SILENT 54 #define subtitle_mgr_err(x...) do { printf(x); } while (0) 55 #else 56 #define subtitle_mgr_err(x...) 57 #endif 35 #define TRACKWRAP 10 58 36 59 37 /* Error Constants */ … … 72 50 73 51 static Track_t * Tracks = NULL; 52 static int TrackSlotCount = 0; 74 53 static int TrackCount = 0; 75 54 static int CurrentTrack = -1; //no as default. … … 88 67 subtitle_mgr_printf(10, "%s::%s %s %s %d\n", FILENAME, __FUNCTION__, track.Name, track.Encoding, track.Id); 89 68 90 if (Tracks == NULL) 91 { 92 Tracks = malloc(sizeof(Track_t) * TRACKWRAP); 93 for (i = 0; i < TRACKWRAP; ++i) 94 { 95 Tracks[i].Id = -1; 69 if (TrackCount == TrackSlotCount) 70 { 71 static Track_t *t; 72 t = realloc(Tracks, (TrackSlotCount + TRACKWRAP) * sizeof(Track_t)); 73 if (t) 74 { 75 Tracks = t; 76 TrackSlotCount += TRACKWRAP; 77 for (i = TrackCount; i < TrackSlotCount; ++i) 78 { 79 Tracks[i].Id = -1; 80 } 81 } 82 else 83 { 84 subtitle_mgr_err("%s:%s realloc failed\n", FILENAME, __FUNCTION__); 85 return cERR_SUBTITLE_MGR_ERROR; 96 86 } 97 87 } … … 104 94 105 95 106 for (i = 0; i < T RACKWRAP; ++i)96 for (i = 0; i < TrackSlotCount; ++i) 107 97 { 108 98 if (Tracks[i].Id == track.Id) … … 113 103 } 114 104 115 if (TrackCount < T RACKWRAP)105 if (TrackCount < TrackSlotCount) 116 106 { 117 107 copyTrack(&Tracks[TrackCount], &track); … … 120 110 else 121 111 { 122 subtitle_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, T RACKWRAP);112 subtitle_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TrackSlotCount); 123 113 return cERR_SUBTITLE_MGR_ERROR; 124 114 } … … 189 179 } 190 180 TrackCount = 0; 181 TrackSlotCount = 0; 191 182 context->playback->isSubtitle = 0; 192 183 } -
titan/libeplayer3/manager/video.c
r40322 r44958 27 27 #include "manager.h" 28 28 #include "common.h" 29 #include "debug.h" 29 30 30 31 /* ***************************** */ … … 32 33 /* ***************************** */ 33 34 #define TRACKWRAP 4 34 35 #ifdef SAM_WITH_DEBUG36 #define VIDEO_MGR_DEBUG37 #else38 #define VIDEO_MGR_SILENT39 #endif40 41 #ifdef VIDEO_MGR_DEBUG42 43 static short debug_level = 0;44 45 #define video_mgr_printf(level, x...) do { \46 if (debug_level >= level) printf(x); } while (0)47 #else48 #define video_mgr_printf(level, x...)49 #endif50 51 #ifndef VIDEO_MGR_SILENT52 #define video_mgr_err(x...) do { printf(x); } while (0)53 #else54 #define video_mgr_err(x...)55 #endif56 57 35 /* Error Constants */ 58 36 #define cERR_VIDEO_MGR_NO_ERROR 0 59 37 #define cERR_VIDEO_MGR_ERROR -1 60 38 61 static const char FILENAME[] = __FILE__;62 63 39 /* ***************************** */ 64 40 /* Types */ … … 68 44 /* Varaibles */ 69 45 /* ***************************** */ 70 71 static Track_t * Tracks = NULL; 46 static Track_t *Tracks = NULL; 72 47 static int TrackCount = 0; 73 48 static int CurrentTrack = 0; //TRACK[0] as default. 74 49 75 50 static void (* updatedTrackInfoFnc)(void) = NULL; 51 76 52 /* ***************************** */ 77 53 /* Prototypes */ … … 83 59 84 60 static int ManagerAdd(Context_t *context, Track_t track) { 85 video_mgr_printf(10, " %s::%s\n", FILENAME, __FUNCTION__);61 video_mgr_printf(10, "\n"); 86 62 87 63 if (Tracks == NULL) … … 97 73 if (Tracks == NULL) 98 74 { 99 video_mgr_err(" %s:%s malloc failed\n", FILENAME, __FUNCTION__);75 video_mgr_err("malloc failed\n"); 100 76 return cERR_VIDEO_MGR_ERROR; 101 77 } … … 118 94 else 119 95 { 120 video_mgr_err(" %s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TRACKWRAP);96 video_mgr_err("TrackCount out if range %d - %d\n", TrackCount, TRACKWRAP); 121 97 return cERR_VIDEO_MGR_ERROR; 122 98 } … … 127 103 } 128 104 129 video_mgr_printf(10, " %s::%s\n", FILENAME, __FUNCTION__);105 video_mgr_printf(10, "\n"); 130 106 return cERR_VIDEO_MGR_NO_ERROR; 131 107 } … … 136 112 char ** tracklist = NULL; 137 113 138 video_mgr_printf(10, " %s::%s\n", FILENAME, __FUNCTION__);114 video_mgr_printf(10, "\n"); 139 115 140 116 if (Tracks != NULL) … … 145 121 if (tracklist == NULL) 146 122 { 147 video_mgr_err(" %s:%s malloc failed\n", FILENAME, __FUNCTION__);123 video_mgr_err("malloc failed\n"); 148 124 return NULL; 149 125 } … … 164 140 } 165 141 166 video_mgr_printf(10, " %s::%s return %p (%d - %d)\n", FILENAME, __FUNCTION__, tracklist, j, TrackCount);142 video_mgr_printf(10, "return %p (%d - %d)\n", tracklist, j, TrackCount); 167 143 return tracklist; 168 144 } … … 172 148 int i = 0; 173 149 174 video_mgr_printf(10, " %s::%s\n", FILENAME, __FUNCTION__);150 video_mgr_printf(10, "\n"); 175 151 176 152 if(Tracks != NULL) … … 185 161 else 186 162 { 187 video_mgr_err(" %s::%s nothing to delete!\n", FILENAME, __FUNCTION__);163 video_mgr_err("nothing to delete!\n"); 188 164 return cERR_VIDEO_MGR_ERROR; 189 165 } … … 193 169 context->playback->isVideo = 0; 194 170 195 video_mgr_printf(10, " %s::%s return no error\n", FILENAME, __FUNCTION__);171 video_mgr_printf(10, "return no error\n"); 196 172 return cERR_VIDEO_MGR_NO_ERROR; 197 173 } … … 201 177 int ret = cERR_VIDEO_MGR_NO_ERROR; 202 178 203 video_mgr_printf(10, " %s::%s\n", FILENAME, __FUNCTION__);179 video_mgr_printf(10, "\n"); 204 180 205 181 switch(command) … … 257 233 case MANAGER_GET_TRACK: 258 234 { 259 video_mgr_printf(20, " %s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__);235 video_mgr_printf(20, "MANAGER_GET_TRACK\n"); 260 236 261 237 if ((TrackCount > 0) && (CurrentTrack >=0)) … … 307 283 if (i == TrackCount) 308 284 { 309 video_mgr_err(" %s::%s track id %d unknown\n", FILENAME, __FUNCTION__, *((int*)argument));285 video_mgr_err("track id %d unknown\n", *((int*)argument)); 310 286 ret = cERR_VIDEO_MGR_ERROR; 311 287 } … … 338 314 } 339 315 default: 340 video_mgr_err(" %s::%s ContainerCmd %d not supported!\n", FILENAME, __FUNCTION__, command);316 video_mgr_err("ContainerCmd %d not supported!\n", command); 341 317 ret = cERR_VIDEO_MGR_ERROR; 342 318 break; 343 319 } 344 320 345 video_mgr_printf(10, " %s:%s: returning %d\n", FILENAME, __FUNCTION__,ret);321 video_mgr_printf(10, "returning %d\n", ret); 346 322 return ret; 347 323 } -
titan/libeplayer3/output/linuxdvb_mipsel.c
r42431 r44958 23 23 24 24 #include <stdio.h> 25 #include <inttypes.h> 25 26 #include <string.h> 26 27 #include <stdlib.h> 27 28 #include <unistd.h> 29 #include <stdbool.h> 28 30 #include <fcntl.h> 29 31 #include <sys/types.h> … … 41 43 42 44 #include "common.h" 45 #include "debug.h" 43 46 #include "output.h" 44 47 #include "writer.h" … … 50 53 /* ***************************** */ 51 54 52 //#define LINUXDVB_DEBUG53 #define LINUXDVB_SILENT54 55 static unsigned short debug_level = 0;56 57 static const char FILENAME[] = __FILE__;58 59 #ifdef LINUXDVB_DEBUG60 #define linuxdvb_printf(level, fmt, x...) do { \61 if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x ); } while (0)62 #else63 #define linuxdvb_printf(x...)64 #endif65 66 #ifndef LINUXDVB_SILENT67 #define linuxdvb_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)68 #else69 #define linuxdvb_err(x...)70 #endif71 72 55 #define cERR_LINUXDVB_NO_ERROR 0 73 56 #define cERR_LINUXDVB_ERROR -1 74 57 75 static const char VIDEODEV[] 76 static const char AUDIODEV[] 58 static const char VIDEODEV[] = "/dev/dvb/adapter0/video0"; 59 static const char AUDIODEV[] = "/dev/dvb/adapter0/audio0"; 77 60 78 61 static int videofd = -1; … … 89 72 90 73 unsigned long long int sCURRENT_PTS = 0; 74 bool isBufferedOutput = false; 91 75 92 76 pthread_mutex_t LinuxDVBmutex; … … 95 79 /* Prototypes */ 96 80 /* ***************************** */ 81 int32_t LinuxDvbBuffOpen(Context_t *context, char *type, int outfd, void *mtx); 82 int32_t LinuxDvbBuffClose(Context_t *context); 83 int32_t LinuxDvbBuffFlush(Context_t *context); 84 int32_t LinuxDvbBuffResume(Context_t *context); 85 86 ssize_t BufferingWriteV(int fd, const struct iovec *iov, int ic); 87 int32_t LinuxDvbBuffSetSize(const uint32_t bufferSize); 88 uint32_t LinuxDvbBuffGetSize(); 89 97 90 int LinuxDvbStop(Context_t *context, char * type); 98 91 … … 101 94 /* ***************************** */ 102 95 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 107 pthread_mutex_lock(&LinuxDVBmutex); 108 109 linuxdvb_printf(250, "received mutex\n"); 110 } 111 112 void releaseLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { 113 pthread_mutex_unlock(&LinuxDVBmutex); 114 115 linuxdvb_printf(250, "released mutex\n"); 116 117 } 118 119 static int LinuxDvbMapBypassMode(int bypass) 120 { 121 if( 0x30 == bypass && IsDreambox() ) 122 { 123 return 0x0f; 124 } 96 #define getLinuxDVBMutex() pthread_mutex_lock(&LinuxDVBmutex) 97 #define releaseLinuxDVBMutex() pthread_mutex_unlock(&LinuxDVBmutex) 98 99 static int LinuxDvbMapBypassMode(int bypass, bool primary) 100 { 101 if (STB_DREAMBOX == GetSTBType()) { 102 primary = !primary; 103 } 104 105 switch(bypass) { 106 case AUDIOTYPE_RAW: 107 bypass = primary ? 0x30 : 0xf; 108 break; 109 case AUDIOTYPE_AC3_PLUS: 110 bypass = primary ? 0x22 : 7; 111 break; 112 case AUDIOTYPE_WMA: 113 bypass = primary ? 0x20 : 0xd; 114 break; 115 case AUDIOTYPE_WMA_PRO: 116 bypass = primary ? 0x21 : 0xe; 117 break; 118 default: 119 break; 120 }; 121 125 122 return bypass; 126 123 } 127 124 128 int LinuxDvbOpen(Context_t *context __attribute__((unused)), char * type) { 129 unsigned char video = !strcmp("video", type); 130 unsigned char audio = !strcmp("audio", type); 125 static int LinuxDvbMapStreamType(int streamtype, bool primary) 126 { 127 if (STB_DREAMBOX == GetSTBType()) { 128 primary = !primary; 129 } 130 131 switch(streamtype) { 132 case STREAMTYPE_MPEG4_H265: 133 streamtype = primary ? 7 : 22; 134 break; 135 case STREAMTYPE_VC1: 136 streamtype = primary ? 3 : 16; 137 break; 138 case STREAMTYPE_VC1_SM: 139 streamtype = primary ? 5 : 17; 140 break; 141 case STREAMTYPE_VB8: 142 streamtype = primary ? 8 : 20; 143 break; 144 case STREAMTYPE_VB9: 145 streamtype = primary ? 9 : 23; 146 break; 147 default: 148 break; 149 }; 150 151 return streamtype; 152 } 153 154 int LinuxDvbOpen(Context_t *context __attribute__((unused)), char *type) 155 { 156 uint8_t video = !strcmp("video", type); 157 uint8_t audio = !strcmp("audio", type); 131 158 132 159 linuxdvb_printf(10, "v%d a%d\n", video, audio); … … 138 165 if (videofd < 0) 139 166 { 140 linuxdvb_err("failed to open %s - errno %d\n", VIDEODEV, errno); 141 linuxdvb_err("%s\n", strerror(errno)); 167 linuxdvb_err("failed to open %s - errno %d, %s\n", VIDEODEV, errno, strerror(errno)); 142 168 return cERR_LINUXDVB_ERROR; 143 169 } … … 145 171 if (ioctl( videofd, VIDEO_CLEAR_BUFFER) == -1) 146 172 { 147 linuxdvb_err("ioctl failed with errno %d\n", errno); 148 linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); 173 linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 149 174 } 150 175 151 176 if (ioctl( videofd, VIDEO_SELECT_SOURCE, (void*)VIDEO_SOURCE_MEMORY) == -1) 152 177 { 153 linuxdvb_err("ioctl failed with errno %d\n", errno); 154 linuxdvb_err("VIDEO_SELECT_SOURCE: %s\n", strerror(errno)); 178 linuxdvb_err("VIDEO_SELECT_SOURCE: ERROR %d, %s\n", errno, strerror(errno)); 155 179 } 156 180 157 181 if (ioctl(videofd, VIDEO_FREEZE) == -1) 158 182 { 159 linuxdvb_err("ioctl failed with errno %d\n", errno); 160 linuxdvb_err("VIDEO_FREEZE: %s\n", strerror(errno)); 161 } 162 183 linuxdvb_err("VIDEO_FREEZE: ERROR %d, %s\n", errno, strerror(errno)); 184 } 185 186 if (isBufferedOutput) 187 LinuxDvbBuffOpen(context, type, videofd, &LinuxDVBmutex); 163 188 } 164 189 if (audio && audiofd < 0) … … 168 193 if (audiofd < 0) 169 194 { 170 linuxdvb_err("failed to open %s - errno %d\n", AUDIODEV, errno); 171 linuxdvb_err("%s\n", strerror(errno)); 172 195 linuxdvb_err("failed to open %s - errno %d, %s\n", AUDIODEV, errno, strerror(errno)); 173 196 return cERR_LINUXDVB_ERROR; 174 197 } … … 176 199 if (ioctl( audiofd, AUDIO_CLEAR_BUFFER) == -1) 177 200 { 178 linuxdvb_err("ioctl failed with errno %d\n", errno); 179 linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); 201 linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 180 202 } 181 203 182 204 if (ioctl( audiofd, AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) == -1) 183 205 { 184 linuxdvb_err("ioctl failed with errno %d\n", errno); 185 linuxdvb_err("AUDIO_SELECT_SOURCE: %s\n", strerror(errno)); 206 linuxdvb_err("AUDIO_SELECT_SOURCE: ERROR %d, %s\n", errno, strerror(errno)); 186 207 } 187 208 188 209 if (ioctl( audiofd, AUDIO_PAUSE) == -1) 189 210 { 190 linuxdvb_err("ioctl failed with errno %d\n", errno); 191 linuxdvb_err("AUDIO_PAUSE: %s\n", strerror(errno)); 211 linuxdvb_err("AUDIO_PAUSE: ERROR %d, %s\n", errno, strerror(errno)); 192 212 } 193 213 214 if (isBufferedOutput) 215 LinuxDvbBuffOpen(context, type, audiofd, &LinuxDVBmutex); 194 216 } 195 217 … … 197 219 } 198 220 199 int LinuxDvbClose(Context_t *context, char * 200 { 201 u nsigned charvideo = !strcmp("video", type);202 u nsigned charaudio = !strcmp("audio", type);221 int LinuxDvbClose(Context_t *context, char *type) 222 { 223 uint8_t video = !strcmp("video", type); 224 uint8_t audio = !strcmp("audio", type); 203 225 204 226 linuxdvb_printf(10, "v%d a%d\n", video, audio); … … 210 232 LinuxDvbStop(context, type); 211 233 212 getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 234 getLinuxDVBMutex(); 235 236 if (isBufferedOutput) 237 LinuxDvbBuffClose(context); 213 238 214 239 if (video && videofd != -1) … … 223 248 } 224 249 225 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);250 releaseLinuxDVBMutex(); 226 251 return cERR_LINUXDVB_NO_ERROR; 227 252 } 228 253 229 int LinuxDvbPlay(Context_t *context, char * 230 int ret = cERR_LINUXDVB_NO_ERROR;231 Writer_t *writer;232 233 u nsigned charvideo = !strcmp("video", type);234 u nsigned charaudio = !strcmp("audio", type);254 int LinuxDvbPlay(Context_t *context, char *type) { 255 int32_t ret = cERR_LINUXDVB_NO_ERROR; 256 Writer_t *writer; 257 258 uint8_t video = !strcmp("video", type); 259 uint8_t audio = !strcmp("audio", type); 235 260 236 261 linuxdvb_printf(10, "v%d a%d\n", video, audio); 237 262 238 263 if (video && videofd != -1) { 239 char * 264 char *Encoding = NULL; 240 265 context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding); 241 266 … … 243 268 244 269 writer = getWriter(Encoding); 245 246 // SULGE VU 4K dont like this247 /*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 256 270 if (writer == NULL) 257 271 { … … 262 276 { 263 277 linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding); 264 if (ioctl( videofd, VIDEO_SET_STREAMTYPE, (void*) writer->caps->dvbStreamType) == -1) 265 { 266 linuxdvb_err("ioctl failed with errno %d\n", errno); 267 linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno)); 278 ret = ioctl( videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, true)); 279 if (ret < 0) ret = ioctl( videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, false)); 280 if (ret < 0) 281 { 282 linuxdvb_err("VIDEO_SET_STREAMTYPE: ERROR %d, %s\n", errno, strerror(errno)); 268 283 ret = cERR_LINUXDVB_ERROR; 269 284 } … … 273 288 if (0 != ioctl(videofd, VIDEO_PLAY)) 274 289 { 275 linuxdvb_err("ioctl failed with errno %d\n", errno); 276 linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno)); 290 linuxdvb_err("VIDEO_PLAY: ERROR %d, %s\n", errno, strerror(errno)); 277 291 ret = cERR_LINUXDVB_ERROR; 278 292 } … … 280 294 if (ioctl(videofd, VIDEO_CONTINUE) == -1) 281 295 { 282 linuxdvb_err("ioctl failed with errno %d\n", errno); 283 linuxdvb_err("VIDEO_CONTINUE: %s\n", strerror(errno)); 296 linuxdvb_err("VIDEO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno)); 284 297 } 285 298 286 299 if (ioctl( videofd, VIDEO_CLEAR_BUFFER) == -1) 287 300 { 288 linuxdvb_err("ioctl failed with errno %d\n", errno); 289 linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); 301 linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 290 302 } 291 303 } … … 298 310 writer = getWriter(Encoding); 299 311 300 // SULGE VU 4K dont like this301 /*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 310 312 if (writer == NULL) 311 313 { … … 316 318 { 317 319 linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding); 318 if (ioctl( audiofd, AUDIO_SET_BYPASS_MODE, (void*) LinuxDvbMapBypassMode(writer->caps->dvbStreamType)) < 0) 319 { 320 linuxdvb_err("ioctl failed with errno %d\n", errno); 321 linuxdvb_err("AUDIO_SET_BYPASS_MODE: %s\n", strerror(errno)); 320 ret = ioctl( audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, true)); 321 if (ret < 0) ret = ioctl( audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, false)); 322 if (ret < 0) 323 { 324 linuxdvb_err("AUDIO_SET_BYPASS_MODE: ERROR %d, %s\n", errno, strerror(errno)); 322 325 ret = cERR_LINUXDVB_ERROR; 323 326 } … … 326 329 if (ioctl(audiofd, AUDIO_PLAY) < 0) 327 330 { 328 linuxdvb_err("ioctl failed with errno %d\n", errno); 329 linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); 331 linuxdvb_err("AUDIO_PLAY: ERROR %d, %s\n", errno, strerror(errno)); 330 332 ret = cERR_LINUXDVB_ERROR; 331 333 } … … 333 335 if (ioctl(audiofd, AUDIO_CONTINUE) < 0) 334 336 { 335 linuxdvb_err("ioctl failed with errno %d\n", errno); 336 linuxdvb_err("AUDIO_CONTINUE: %s\n", strerror(errno)); 337 linuxdvb_err("AUDIO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno)); 337 338 ret = cERR_LINUXDVB_ERROR; 338 339 } … … 352 353 linuxdvb_printf(10, "v%d a%d\n", video, audio); 353 354 354 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);355 getLinuxDVBMutex(); 355 356 356 357 if (video && videofd != -1) … … 358 359 if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) 359 360 { 360 linuxdvb_err("ioctl failed with errno %d\n", errno); 361 linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); 361 linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 362 362 } 363 363 364 364 if (ioctl(videofd, VIDEO_STOP) == -1) 365 365 { 366 linuxdvb_err("ioctl failed with errno %d\n", errno); 367 linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno)); 366 linuxdvb_err("VIDEO_STOP: ERROR %d, %s\n", errno, strerror(errno)); 368 367 ret = cERR_LINUXDVB_ERROR; 369 368 } … … 371 370 ioctl(videofd, VIDEO_SLOWMOTION, 0); 372 371 ioctl(videofd, VIDEO_FAST_FORWARD, 0); 373 374 372 ioctl(videofd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX); 375 373 } … … 377 375 if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) 378 376 { 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 // } 377 linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 378 } 379 389 380 if (ioctl(audiofd, AUDIO_STOP) == -1) 390 381 { 391 linuxdvb_err("ioctl failed with errno %d\n", errno); 392 linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); 382 linuxdvb_err("AUDIO_STOP: ERROR %d, %s\n", errno, strerror(errno)); 393 383 ret = cERR_LINUXDVB_ERROR; 394 384 } … … 396 386 } 397 387 398 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);399 400 return ret; 401 } 402 403 int LinuxDvbPause(Context_t *context __attribute__((unused)), char * 404 int ret = cERR_LINUXDVB_NO_ERROR;405 u nsigned charvideo = !strcmp("video", type);406 u nsigned charaudio = !strcmp("audio", type);388 releaseLinuxDVBMutex(); 389 390 return ret; 391 } 392 393 int LinuxDvbPause(Context_t *context __attribute__((unused)), char *type) { 394 int32_t ret = cERR_LINUXDVB_NO_ERROR; 395 uint8_t video = !strcmp("video", type); 396 uint8_t audio = !strcmp("audio", type); 407 397 408 398 linuxdvb_printf(10, "v%d a%d\n", video, audio); 409 399 410 getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 411 412 if (video && videofd != -1) { 400 getLinuxDVBMutex(); 401 402 if (video && videofd != -1) 403 { 413 404 if (ioctl(videofd, VIDEO_FREEZE, NULL) == -1) 414 405 { 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) { 406 linuxdvb_err("VIDEO_FREEZE: ERROR %d, %s\n", errno, strerror(errno)); 407 ret = cERR_LINUXDVB_ERROR; 408 } 409 } 410 411 if (audio && audiofd != -1) 412 { 421 413 if (ioctl(audiofd, AUDIO_PAUSE, NULL) == -1) 422 414 { 423 linuxdvb_err("ioctl failed with errno %d\n", errno); 424 linuxdvb_err("AUDIO_PAUSE: %s\n", strerror(errno)); 425 ret = cERR_LINUXDVB_ERROR; 426 } 427 } 428 429 releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 415 linuxdvb_err("AUDIO_PAUSE: ERROR %d, %s\n", errno, strerror(errno)); 416 ret = cERR_LINUXDVB_ERROR; 417 } 418 } 419 420 releaseLinuxDVBMutex(); 430 421 431 422 return ret; … … 433 424 434 425 int LinuxDvbContinue(Context_t *context __attribute__((unused)), char * type) { 435 int ret = cERR_LINUXDVB_NO_ERROR;436 u nsigned charvideo = !strcmp("video", type);437 u nsigned charaudio = !strcmp("audio", type);426 int32_t ret = cERR_LINUXDVB_NO_ERROR; 427 uint8_t video = !strcmp("video", type); 428 uint8_t audio = !strcmp("audio", type); 438 429 439 430 linuxdvb_printf(10, "v%d a%d\n", video, audio); 440 431 441 if (video && videofd != -1) { 432 if (video && videofd != -1) 433 { 442 434 if (ioctl(videofd, VIDEO_CONTINUE, NULL) == -1) 443 435 { 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) { 436 linuxdvb_err("VIDEO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno)); 437 ret = cERR_LINUXDVB_ERROR; 438 } 439 } 440 441 if (audio && audiofd != -1) 442 { 450 443 if (ioctl(audiofd, AUDIO_CONTINUE, NULL) == -1) 451 444 { 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 } 445 linuxdvb_err("AUDIO_CONTINUE: ERROR %d, %s\n", errno, strerror(errno)); 446 ret = cERR_LINUXDVB_ERROR; 447 } 448 } 449 450 if (isBufferedOutput) 451 LinuxDvbBuffResume(context); 457 452 458 453 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;467 454 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 478 455 return ret; 479 456 } … … 487 464 if(*flag == '1') 488 465 { 489 //AUDIO_SET_MUTE has no effect with new player490 //if (ioctl(audiofd, AUDIO_SET_MUTE, 1) == -1)491 466 if (ioctl(audiofd, AUDIO_STOP, NULL) == -1) 492 467 { 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)); 468 linuxdvb_err("AUDIO_STOP: ERROR %d, %s\n", errno, strerror(errno)); 496 469 ret = cERR_LINUXDVB_ERROR; 497 470 } … … 499 472 else 500 473 { 501 //AUDIO_SET_MUTE has no effect with new player502 //if (ioctl(audiofd, AUDIO_SET_MUTE, 0) == -1)503 474 if (ioctl(audiofd, AUDIO_PLAY) == -1) 504 475 { 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)); 476 linuxdvb_err("AUDIO_PLAY: ERROR %d, %s\n", errno, strerror(errno)); 508 477 ret = cERR_LINUXDVB_ERROR; 509 478 } … … 516 485 } 517 486 518 519 487 int LinuxDvbFlush(Context_t *context __attribute__((unused)), char * type) 520 488 { 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 550 489 return cERR_LINUXDVB_NO_ERROR; 551 490 } 552 491 492 //obi 553 493 #ifndef use_set_speed_instead_ff 554 494 int LinuxDvbFastForward(Context_t *context, char * type) { … … 562 502 if (video && videofd != -1) { 563 503 564 getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 504 // getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 505 getLinuxDVBMutex(); 565 506 566 507 /* konfetti comment: speed is a value given in skipped frames */ … … 573 514 } 574 515 575 releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 516 // releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 517 releaseLinuxDVBMutex(); 576 518 } 577 519 … … 600 542 if (video && videofd != -1) { 601 543 602 getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 544 // getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 545 getLinuxDVBMutex(); 603 546 604 547 speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int)); … … 613 556 // } 614 557 615 releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 558 // releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 559 releaseLinuxDVBMutex(); 616 560 } 617 561 618 562 if (audio && audiofd != -1) { 619 563 620 getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 564 // getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 565 getLinuxDVBMutex(); 621 566 622 567 speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int)); … … 631 576 // } 632 577 633 releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 578 // releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 579 releaseLinuxDVBMutex(); 634 580 } 635 581 … … 645 591 return ret; 646 592 } 593 //obi 647 594 648 595 int LinuxDvbSlowMotion(Context_t *context, char * type) { 649 int ret = cERR_LINUXDVB_NO_ERROR;650 651 u nsigned charvideo = !strcmp("video", type);652 u nsigned charaudio = !strcmp("audio", type);596 int32_t ret = cERR_LINUXDVB_NO_ERROR; 597 598 uint8_t video = !strcmp("video", type); 599 uint8_t audio = !strcmp("audio", type); 653 600 654 601 linuxdvb_printf(10, "v%d a%d\n", video, audio); 655 602 656 603 if ( (video && videofd != -1) || (audio && audiofd != -1) ) { 657 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);604 getLinuxDVBMutex(); 658 605 659 606 if (video && videofd != -1) { 660 607 if (ioctl(videofd, VIDEO_SLOWMOTION, context->playback->SlowMotion) == -1) 661 608 { 662 linuxdvb_err("ioctl failed with errno %d\n", errno); 663 linuxdvb_err("VIDEO_SLOWMOTION: %s\n", strerror(errno)); 609 linuxdvb_err("VIDEO_SLOWMOTION: ERROR %d, %s\n", errno, strerror(errno)); 664 610 ret = cERR_LINUXDVB_ERROR; 665 611 } 666 612 } 667 613 668 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);614 releaseLinuxDVBMutex(); 669 615 } 670 616 … … 674 620 } 675 621 676 int LinuxDvbAVSync(Context_t *context, char * 677 int ret = cERR_LINUXDVB_NO_ERROR;622 int LinuxDvbAVSync(Context_t *context, char *type __attribute__((unused))) { 623 int32_t ret = cERR_LINUXDVB_NO_ERROR; 678 624 /* konfetti: this one is dedicated to audiofd so we 679 625 * are ignoring what is given by type! I think we should … … 683 629 */ 684 630 if (audiofd != -1) { 685 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);631 getLinuxDVBMutex(); 686 632 687 633 if (ioctl(audiofd, AUDIO_SET_AV_SYNC, 0) == -1) //context->playback->AVSync) == -1) 688 634 { 689 linuxdvb_err("ioctl failed with errno %d\n", errno); 690 linuxdvb_err("AUDIO_SET_AV_SYNC: %s\n", strerror(errno)); 691 ret = cERR_LINUXDVB_ERROR; 692 } 693 694 releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 695 } 696 697 return ret; 698 } 699 700 int LinuxDvbClear(Context_t *context __attribute__((unused)), char * type) 635 linuxdvb_err("AUDIO_SET_AV_SYNC: ERROR %d, %s\n", errno, strerror(errno)); 636 ret = cERR_LINUXDVB_ERROR; 637 } 638 639 releaseLinuxDVBMutex(); 640 } 641 642 return ret; 643 } 644 645 int LinuxDvbClear(Context_t *context __attribute__((unused)), char *type) 701 646 { 702 647 int32_t ret = cERR_LINUXDVB_NO_ERROR; … … 704 649 uint8_t audio = !strcmp("audio", type); 705 650 706 linuxdvb_printf(10, " >>>>>>>>>>LinuxDvbClear v%d a%d\n", video, audio);651 linuxdvb_printf(10, "LinuxDvbClear v%d a%d\n", video, audio); 707 652 708 653 if ( (video && videofd != -1) || (audio && audiofd != -1) ) 709 654 { 710 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);655 getLinuxDVBMutex(); 711 656 712 657 if (video && videofd != -1) … … 714 659 if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) 715 660 { 716 linuxdvb_err("ioctl failed with errno %d\n", errno); 717 linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); 661 linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 718 662 ret = cERR_LINUXDVB_ERROR; 719 663 } … … 723 667 if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) 724 668 { 725 linuxdvb_err("ioctl failed with errno %d\n", errno); 726 linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); 669 linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 727 670 ret = cERR_LINUXDVB_ERROR; 728 671 } 729 672 } 730 673 731 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);674 releaseLinuxDVBMutex(); 732 675 } 733 676 … … 738 681 739 682 int LinuxDvbPts(Context_t *context __attribute__((unused)), unsigned long long int* pts) { 740 int ret = cERR_LINUXDVB_ERROR;683 int32_t ret = cERR_LINUXDVB_ERROR; 741 684 742 685 linuxdvb_printf(50, "\n"); 743 686 744 // pts is a non writting requests and can be done in parallel to other requests 745 //getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 746 687 // GET_PTS is immutable call, so it can be done in parallel to other requests 747 688 if (videofd > -1 && !ioctl(videofd, VIDEO_GET_PTS, (void*)&sCURRENT_PTS)) 748 689 { … … 751 692 else 752 693 { 753 linuxdvb_err("VIDEO_GET_PTS: %d (%s)\n", errno, strerror(errno));694 linuxdvb_err("VIDEO_GET_PTS: ERROR %d, %s\n", errno, strerror(errno)); 754 695 } 755 696 … … 762 703 else 763 704 { 764 linuxdvb_err("AUDIO_GET_PTS: %d (%s)\n", errno, strerror(errno));705 linuxdvb_err("AUDIO_GET_PTS: ERROR %d, %s\n", errno, strerror(errno)); 765 706 } 766 707 } … … 772 713 773 714 *((unsigned long long int *)pts)=(unsigned long long int)sCURRENT_PTS; 774 775 //releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__);776 777 715 return ret; 778 716 } … … 780 718 int LinuxDvbGetFrameCount(Context_t *context __attribute__((unused)), unsigned long long int* frameCount) 781 719 { 782 int ret =cERR_LINUXDVB_NO_ERROR;783 return ret; 784 } 785 786 int LinuxDvbSwitch(Context_t *context, char * type) 787 { 788 u nsigned char audio = !strcmp("audio", type);789 unsigned char video = !strcmp("video", type);790 Writer_t* writer;720 return cERR_LINUXDVB_NO_ERROR; 721 } 722 723 int LinuxDvbSwitch(Context_t *context, char *type) 724 { 725 uint8_t audio = !strcmp("audio", type); 726 uint8_t video = !strcmp("video", type); 727 Writer_t *writer; 728 int ret = 0; 791 729 792 730 linuxdvb_printf(10, "v%d a%d\n", video, audio); 793 731 794 732 if ( (video && videofd != -1) || (audio && audiofd != -1) ) { 795 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);733 getLinuxDVBMutex(); 796 734 797 735 if (audio && audiofd != -1) { … … 806 744 if (ioctl(audiofd, AUDIO_STOP ,NULL) == -1) 807 745 { 808 linuxdvb_err("ioctl failed with errno %d\n", errno); 809 linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); 810 746 linuxdvb_err("AUDIO_STOP: ERROR %d, %s\n", errno, strerror(errno)); 811 747 } 812 748 813 749 if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) 814 750 { 815 linuxdvb_err("ioctl failed with errno %d\n", errno); 816 linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); 817 751 linuxdvb_err("AUDIO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 818 752 } 819 753 … … 821 755 { 822 756 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 757 } 758 else 829 759 { 830 760 linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding); 831 if (ioctl( audiofd, AUDIO_SET_BYPASS_MODE, (void*) LinuxDvbMapBypassMode(writer->caps->dvbStreamType)) == -1) 761 ret = ioctl( audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, true)); 762 if (ret < 0) ret = ioctl( audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, false)); 763 if (ret < 0) 832 764 { 833 linuxdvb_err("ioctl failed with errno %d\n", errno); 834 linuxdvb_err("AUDIO_SET_BYPASS_MODE: %s\n", strerror(errno)); 765 linuxdvb_err("AUDIO_SET_BYPASS_MODE: ERROR %d, %s\n", errno, strerror(errno)); 835 766 } 836 767 } … … 838 769 if (ioctl(audiofd, AUDIO_PLAY) == -1) 839 770 { 840 linuxdvb_err("ioctl failed with errno %d\n", errno); 841 linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); 771 linuxdvb_err("AUDIO_PLAY: ERROR %d, %s\n", errno, strerror(errno)); 842 772 } 843 773 free(Encoding); … … 854 784 if (ioctl(videofd, VIDEO_STOP ,NULL) == -1) 855 785 { 856 linuxdvb_err("ioctl failed with errno %d\n", errno); 857 linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno)); 786 linuxdvb_err("VIDEO_STOP: ERROR %d, %s\n", errno, strerror(errno)); 858 787 } 859 788 860 789 if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) 861 790 { 862 linuxdvb_err("ioctl failed with errno %d\n", errno); 863 linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); 791 linuxdvb_err("VIDEO_CLEAR_BUFFER: ERROR %d, %s\n", errno, strerror(errno)); 864 792 } 865 793 … … 871 799 { 872 800 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 801 } 802 else 879 803 { 880 804 linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding); 881 if (ioctl( videofd, VIDEO_SET_STREAMTYPE, (void*) writer->caps->dvbStreamType) == -1) 805 ret = ioctl( videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, true)); 806 if (ret < 0) ret = ioctl( videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, false)); 807 if (ret < 0) 882 808 { 883 linuxdvb_err("ioctl failed with errno %d\n", errno); 884 linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno)); 809 linuxdvb_err("VIDEO_SET_STREAMTYPE: ERROR %d, %s\n", errno, strerror(errno)); 885 810 } 886 811 } … … 891 816 * return an error here and stop the playback mode 892 817 */ 893 linuxdvb_err("ioctl failed with errno %d\n", errno); 894 linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno)); 818 linuxdvb_err("VIDEO_PLAY:ERROR %d, %s\n", errno, strerror(errno)); 895 819 } 896 820 free(Encoding); … … 900 824 } 901 825 902 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);826 releaseLinuxDVBMutex(); 903 827 904 828 } … … 909 833 } 910 834 911 static int Write(void *_context, void *_out)835 static int Write(void *_context, void *_out) 912 836 { 913 837 Context_t *context = (Context_t *) _context; 914 838 AudioVideoOut_t *out = (AudioVideoOut_t*) _out; 915 int 916 int 917 u nsigned charvideo = 0;918 u nsigned charaudio = 0;919 Writer_t * writer;839 int32_t ret = cERR_LINUXDVB_NO_ERROR; 840 int32_t res = 0; 841 uint8_t video = 0; 842 uint8_t audio = 0; 843 Writer_t *writer = NULL; 920 844 WriterAVCallData_t call; 921 845 … … 929 853 audio = !strcmp("audio", out->type); 930 854 931 linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=% llu FrameRate=%f\n",855 linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%"PRIu64" FrameRate=%d\n", 932 856 out->len, out->extralen, out->pts, out->frameRate); 933 857 linuxdvb_printf(20, "v%d a%d\n", video, audio); … … 935 859 if (video) 936 860 { 937 char * 861 char *Encoding = NULL; 938 862 context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding); 939 863 … … 969 893 else 970 894 { 895 bool changed = false; 971 896 if (evt.type == VIDEO_EVENT_SIZE_CHANGED) 972 897 { 973 linuxdvb_printf(10, "VIDEO_EVENT_SIZE_CHANGED \n", evt.type);898 linuxdvb_printf(10, "VIDEO_EVENT_SIZE_CHANGED type: 0x%x\n", evt.type); 974 899 linuxdvb_printf(10, "width : %d\n", evt.u.size.w); 975 900 linuxdvb_printf(10, "height : %d\n", evt.u.size.h); … … 978 903 videoInfo.height = evt.u.size.h; 979 904 videoInfo.aspect_ratio = evt.u.size.aspect_ratio; 905 changed = true; 980 906 } 981 907 else if (evt.type == VIDEO_EVENT_FRAME_RATE_CHANGED) 982 908 { 983 linuxdvb_printf(10, "VIDEO_EVENT_FRAME_RATE_CHANGED \n", evt.type);909 linuxdvb_printf(10, "VIDEO_EVENT_FRAME_RATE_CHANGED type: 0x%x\n", evt.type); 984 910 linuxdvb_printf(10, "framerate : %d\n", evt.u.frame_rate); 985 911 videoInfo.frame_rate = evt.u.frame_rate; 912 changed = true; 986 913 } 987 914 else if (evt.type == 16 /*VIDEO_EVENT_PROGRESSIVE_CHANGED*/) 988 915 { 989 linuxdvb_printf(10, "VIDEO_EVENT_PROGRESSIVE_CHANGED \n", evt.type);916 linuxdvb_printf(10, "VIDEO_EVENT_PROGRESSIVE_CHANGED type: 0x%x\n", evt.type); 990 917 linuxdvb_printf(10, "progressive : %d\n", evt.u.frame_rate); 991 918 videoInfo.progressive = evt.u.frame_rate; 992 919 context->manager->video->Command(context, MANAGER_UPDATED_TRACK_INFO, NULL); 920 changed = true; 993 921 } 994 922 else 995 923 { 996 924 linuxdvb_err("unhandled DVBAPI Video Event %d\n", evt.type); 925 } 926 927 if (changed && 928 videoInfo.width != -1 && 929 videoInfo.height != -1 && 930 videoInfo.aspect_ratio != -1 && 931 videoInfo.frame_rate != -1 && 932 videoInfo.progressive != -1) 933 { 934 E2iSendMsg("{\"v_e\":{\"w\":%d,\"h\":%d,\"a\":%d,\"f\":%d,\"p\":%d}}\n", 935 videoInfo.width, videoInfo.height, videoInfo.aspect_ratio, videoInfo.frame_rate, videoInfo.progressive); 997 936 } 998 937 } … … 1011 950 call.Height = out->height; 1012 951 call.InfoFlags = out->infoFlags; 1013 call.Version = 0; // is unsingned char 952 call.Version = 0; 953 call.WriteV = isBufferedOutput ? BufferingWriteV : writev_with_retry; 1014 954 1015 955 if (writer->writeData) … … 1030 970 else if (audio) 1031 971 { 1032 char * 972 char *Encoding = NULL; 1033 973 context->manager->audio->Command(context, MANAGER_GETENCODING, &Encoding); 1034 974 1035 linuxdvb_printf(20, " %s::%s Encoding = %s\n", FILENAME, __FUNCTION__, Encoding);975 linuxdvb_printf(20, "Encoding = %s\n", Encoding); 1036 976 1037 977 writer = getWriter(Encoding); … … 1060 1000 call.FrameScale = out->timeScale; 1061 1001 call.InfoFlags = out->infoFlags; 1062 call.Version = 0; /* -1; unsigned char cannot be negative */ 1002 call.Version = 0; 1003 call.WriteV = isBufferedOutput ? BufferingWriteV : writev_with_retry; 1063 1004 1064 1005 if (writer->writeData) … … 1117 1058 free(Encoding); 1118 1059 1060 if (isBufferedOutput) 1061 LinuxDvbBuffFlush(context); 1062 1119 1063 return ret; 1120 1064 } … … 1162 1106 break; 1163 1107 } 1108 //obi 1164 1109 case OUTPUT_FASTFORWARD: { 1165 1110 return LinuxDvbFastForward(context, (char*)argument); … … 1170 1115 break; 1171 1116 } 1117 //obi 1172 1118 case OUTPUT_AVSYNC: { 1173 1119 ret = LinuxDvbAVSync(context, (char*)argument); … … 1175 1121 } 1176 1122 case OUTPUT_CLEAR: { 1123 reset(context); 1177 1124 ret = LinuxDvbClear(context, (char*)argument); 1178 1125 reset(context); … … 1198 1145 break; 1199 1146 } 1200 case OUTPUT_DISCONTINUITY_REVERSE: {1201 return LinuxDvbReverseDiscontinuity(context, (int*)argument);1202 break;1203 }1204 1147 case OUTPUT_GET_FRAME_COUNT: { 1205 1148 unsigned long long int frameCount = 0; … … 1211 1154 ret = cERR_LINUXDVB_NO_ERROR; 1212 1155 *((int*)argument) = videoInfo.progressive; 1156 break; 1157 } 1158 case OUTPUT_SET_BUFFER_SIZE: { 1159 ret = cERR_LINUXDVB_ERROR; 1160 if (!isBufferedOutput) 1161 { 1162 uint32_t bufferSize = *((uint32_t*)argument); 1163 ret = cERR_LINUXDVB_NO_ERROR; 1164 if (bufferSize > 0) 1165 { 1166 LinuxDvbBuffSetSize(bufferSize); 1167 isBufferedOutput = true; 1168 } 1169 } 1170 break; 1171 } 1172 case OUTPUT_GET_BUFFER_SIZE: { 1173 ret = cERR_LINUXDVB_NO_ERROR; 1174 *((uint32_t*)argument) = LinuxDvbBuffGetSize(); 1213 1175 break; 1214 1176 } -
titan/libeplayer3/output/linuxdvb_sh4.c
r40348 r44958 32 32 #include <linux/dvb/video.h> 33 33 #include <linux/dvb/audio.h> 34 #include <linux/dvb/stm_ioctls.h>35 34 #include <memory.h> 36 35 #include <asm/types.h> … … 38 37 #include <errno.h> 39 38 #include <poll.h> 39 #include <sys/uio.h> 40 40 41 41 #include "bcm_ioctls.h" 42 #include "stm_ioctls.h" 42 43 43 44 #include "common.h" 45 #include "debug.h" 44 46 #include "output.h" 45 47 #include "writer.h" … … 50 52 /* Makros/Constants */ 51 53 /* ***************************** */ 52 53 //#define LINUXDVB_DEBUG54 #define LINUXDVB_SILENT55 56 static unsigned short debug_level = 0;57 58 static const char FILENAME[] = __FILE__;59 60 #ifdef LINUXDVB_DEBUG61 #define linuxdvb_printf(level, fmt, x...) do { \62 if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x ); } while (0)63 #else64 #define linuxdvb_printf(x...)65 #endif66 67 #ifndef LINUXDVB_SILENT68 #define linuxdvb_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)69 #else70 #define linuxdvb_err(x...)71 #endif72 73 74 54 #define cERR_LINUXDVB_NO_ERROR 0 75 55 #define cERR_LINUXDVB_ERROR -1 … … 90 70 91 71 unsigned long long int sCURRENT_PTS = 0; 72 bool isBufferedOutput = false; 92 73 93 74 pthread_mutex_t LinuxDVBmutex; … … 96 77 /* Prototypes */ 97 78 /* ***************************** */ 79 int32_t LinuxDvbBuffOpen(Context_t *context, char *type, int outfd, void *mtx); 80 int32_t LinuxDvbBuffClose(Context_t *context); 81 int32_t LinuxDvbBuffFlush(Context_t *context); 82 int32_t LinuxDvbBuffResume(Context_t *context); 83 84 ssize_t BufferingWriteV(int fd, const struct iovec *iov, int ic); 85 int32_t LinuxDvbBuffSetSize(const uint32_t bufferSize); 86 uint32_t LinuxDvbBuffGetSize(); 87 98 88 int LinuxDvbStop(Context_t *context, char * type); 99 89 … … 102 92 /* ***************************** */ 103 93 104 void getLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { 105 106 linuxdvb_printf(250, "requesting mutex\n"); 107 108 pthread_mutex_lock(&LinuxDVBmutex); 109 110 linuxdvb_printf(250, "received mutex\n"); 111 } 112 113 void releaseLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { 114 pthread_mutex_unlock(&LinuxDVBmutex); 115 116 linuxdvb_printf(250, "released mutex\n"); 117 118 } 94 #define getLinuxDVBMutex() pthread_mutex_lock(&LinuxDVBmutex) 95 #define releaseLinuxDVBMutex() pthread_mutex_unlock(&LinuxDVBmutex) 119 96 120 97 int LinuxDvbOpen(Context_t *context __attribute__((unused)), char * type) { … … 124 101 linuxdvb_printf(10, "v%d a%d\n", video, audio); 125 102 126 if (video && videofd < 0) { 103 if (video && videofd < 0) 104 { 105 127 106 videofd = open(VIDEODEV, O_RDWR); 128 129 107 if (videofd < 0) 130 108 { … … 158 136 } 159 137 160 } 161 if (audio && audiofd < 0) { 138 if (isBufferedOutput) 139 LinuxDvbBuffOpen(context, type, videofd, &LinuxDVBmutex); 140 } 141 if (audio && audiofd < 0) 142 { 162 143 audiofd = open(AUDIODEV, O_RDWR); 163 164 144 if (audiofd < 0) 165 145 { … … 189 169 linuxdvb_err("AUDIO_SET_STREAMTYPE: %s\n", strerror(errno)); 190 170 } 171 172 if (isBufferedOutput) 173 LinuxDvbBuffOpen(context, type, audiofd, &LinuxDVBmutex); 191 174 } 192 175 … … 194 177 } 195 178 196 int LinuxDvbClose(Context_t *context, char * type) { 197 unsigned char video = !strcmp("video", type); 198 unsigned char audio = !strcmp("audio", type); 179 int LinuxDvbClose(Context_t *context, char * type) 180 { 181 uint8_t video = !strcmp("video", type); 182 uint8_t audio = !strcmp("audio", type); 199 183 200 184 linuxdvb_printf(10, "v%d a%d\n", video, audio); … … 206 190 LinuxDvbStop(context, type); 207 191 208 getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); 192 getLinuxDVBMutex(); 193 194 if (isBufferedOutput) 195 LinuxDvbBuffClose(context); 209 196 210 197 if (video && videofd != -1) … … 219 206 } 220 207 221 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);208 releaseLinuxDVBMutex(); 222 209 return cERR_LINUXDVB_NO_ERROR; 223 210 } … … 243 230 { 244 231 linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding); 245 if (ioctl( videofd, VIDEO_SET_ENCODING, (void*)VIDEO_ENCODING_AUTO) == -1)232 if (ioctl( videofd, VIDEO_SET_ENCODING, VIDEO_ENCODING_AUTO) == -1) 246 233 { 247 234 linuxdvb_err("ioctl failed with errno %d\n", errno); … … 252 239 { 253 240 linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding); 254 if (ioctl( videofd, VIDEO_SET_ENCODING, (void*)writer->caps->dvbEncoding) == -1)241 if (ioctl( videofd, VIDEO_SET_ENCODING, writer->caps->dvbEncoding) == -1) 255 242 { 256 243 linuxdvb_err("ioctl failed with errno %d\n", errno); … … 288 275 { 289 276 linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding); 290 if (ioctl( audiofd, AUDIO_SET_ENCODING, (void*)writer->caps->dvbEncoding) == -1)277 if (ioctl( audiofd, AUDIO_SET_ENCODING, writer->caps->dvbEncoding) == -1) 291 278 { 292 279 linuxdvb_err("ioctl failed with errno %d\n", errno); … … 315 302 linuxdvb_printf(10, "v%d a%d\n", video, audio); 316 303 317 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);304 getLinuxDVBMutex(); 318 305 319 306 if (video && videofd != -1) { … … 358 345 } 359 346 360 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);347 releaseLinuxDVBMutex(); 361 348 362 349 return ret; … … 370 357 linuxdvb_printf(10, "v%d a%d\n", video, audio); 371 358 372 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);359 getLinuxDVBMutex(); 373 360 374 361 if (video && videofd != -1) { … … 389 376 } 390 377 391 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);378 releaseLinuxDVBMutex(); 392 379 393 380 return ret; … … 417 404 } 418 405 } 406 407 if (isBufferedOutput) 408 LinuxDvbBuffResume(context); 419 409 420 410 linuxdvb_printf(10, "exiting\n"); … … 430 420 linuxdvb_printf(50, "\n"); 431 421 432 if (ioctl( videofd, VIDEO_DISCONTINUITY, (void*)dis_type) == -1)422 if (ioctl( videofd, VIDEO_DISCONTINUITY, dis_type) == -1) 433 423 { 434 424 linuxdvb_err("ioctl failed with errno %d\n", errno); … … 486 476 487 477 if ( (video && videofd != -1) || (audio && audiofd != -1) ) { 488 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);478 getLinuxDVBMutex(); 489 479 490 480 if (video && videofd != -1) { … … 504 494 } 505 495 506 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);496 releaseLinuxDVBMutex(); 507 497 } 508 498 … … 523 513 if (video && videofd != -1) { 524 514 525 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);515 getLinuxDVBMutex(); 526 516 527 517 /* konfetti comment: speed is a value given in skipped frames */ … … 534 524 } 535 525 536 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);526 releaseLinuxDVBMutex(); 537 527 } 538 528 … … 561 551 if (video && videofd != -1) { 562 552 563 getLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);553 getLinuxDVBMutex(); 564 554 565 555 speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int)); … … 574 564 } 575 565 576 releaseLinuxDVBMutex( FILENAME, __FUNCTION__,__LINE__);566 releaseLinuxDVBMutex(); 577 567 } 578 568 579 569 if (audio && audiofd != -1) { 580 570 <