//int hls_proxy_main(char *hls_url, int url_size) int hls_proxy_main(void) { REPORT_VERSION("libhls_jni"); char *file_name = "/mnt/sdcard/livetv.ts"; if (hls_create_virtual_file(file_name) != HLS_SUCCESS) goto fail1; /* init libcurl */ curl_http_init(); sem_init(&hls_live_sem, 0, 0); /* [android mode] start mongoose web server */ if (hls_create_thread(&th_hls_mongoose, NULL, hls_mongoose_thread) != HLS_SUCCESS) goto fail1; /* waiting for the hls_mongoose_thread return */ pthread_join(th_hls_mongoose, NULL); hls_info(">>>>>>>>>>>>>>>>>>>[main thread] exit...\n"); sem_destroy(&hls_live_sem); curl_http_uninit(); return HLS_SUCCESS; fail1: return HLS_ERR; }
static void print_usage() { print_msg( "Usage:\n" " esmerge <video-file> <audio-file> <output-file>\n" "\n" ); REPORT_VERSION("esmerge"); print_msg( "\n" " Merge the contents of two Elementary Stream (ES) files, one containing\n" " video data, and the other audio, to produce an output file containing\n" " Transport Stream (TS).\n" "\n" "Files:\n" " <video-file> is the ES file containing video.\n" " <audio-file> is the ES file containing audio.\n" " <output-file> is the resultant TS file.\n" "\n" "Switches:\n" " -err stdout Write error messages to standard output (the default)\n" " -err stderr Write error messages to standard error (Unix traditional)\n" " -quiet, -q Only output error messages.\n" " -verbose, -v Output information about each audio/video frame.\n" " -x Output diagnostic information.\n" "\n" " -h264 The video stream is H.264 (the default)\n" " -avs The video stream is AVS\n" "\n" " -vidrate <hz> Video frame rate in Hz - defaults to 25Hz.\n" "\n" " -rate <hz> Audio sample rate in Hertz - defaults to 44100, i.e., 44.1KHz.\n" " -cd Equivalent to -rate 44100 (CD rate), the default.\n" " -dat Equivalent to -rate 48000 (DAT rate).\n" "\n" " -adts The audio stream is ADTS (the default)\n" " -l2 The audio stream is MPEG layer 2 audio\n" " -mp2adts The audio stream is MPEG-2 style ADTS regardless of ID bit\n" " -mp4adts The audio stream is MPEG-4 style ADTS regardless of ID bit\n" " -ac3 The audio stream is Dolby AC-3 in ATSC\n" "\n" " -patpmtfreq <f> PAT and PMT will be inserted every <f> video frames. \n" " by default, f = 0 and PAT/PMT are inserted only at \n" " the start of the output stream.\n" "\n" "Limitations\n" "===========\n" "For the moment, the video input must be H.264 or AVS, and the audio input\n" "ADTS, AC-3 ATSC or MPEG layer 2. Also, the audio is assumed to have a\n" "constant number of samples per frame.\n" ); }
static void print_usage() { print_msg( "Usage: stream_type [switches] <infile>\n" "\n" ); REPORT_VERSION("stream_type"); print_msg( "\n" " Attempt to determine if an input stream is Transport Stream,\n" " Program Stream, or Elementary Stream, and if the latter, if it\n" " is H.262 or H.264 (i.e., MPEG-2 or MPEG-4/AVC respectively)." "\n" " The mechanisms used are fairly crude, assuming that:\n" " - data is byte aligned\n" " - for TS, the first byte in the file will be the start of a NAL unit,\n" " and PAT/PMT packets will be findable\n" " - for PS, the first packet starts immediately at the start of the\n" " file, and is a pack header\n" " - if the first 1000 packets could be H.262 *or* H.264, then the data\n" " is assumed to be H.264 (the program doesn't try to determine\n" " sensible sequences of H.262/H.264 packets, so this is a reasonable\n" " way of guessing)\n" "\n" " It is quite possible that data which is not relevant will be\n" " misidentified\n" "\n" " The program exit value is:\n" " * 10 if it detects Transport Stream,\n" " * 11 if it detects Program Stream,\n" " * 12 if it detects Elementary Stream containing H.262 (MPEG-2),\n" " * 14 if it detects Elementary Stream containing H.264 (MPEG-4/AVC),\n" " * 5 if it looks like it might be PES,\n" " * 9 if it really cannot decide, or\n" " * 0 if some error occurred\n" "\n" "Files:\n" " <infile> is the file to analyse\n" "\n" "Switches:\n" " -err stdout Write error messages to standard output (the default)\n" " -err stderr Write error messages to standard error (Unix traditional)\n" " -verbose, -v Output more detailed information about how it is\n" " making its decision\n" " -quiet, -q Only output error messages\n" ); }
static void print_usage() { print_msg( "Usage: ts2es [switches] [<infile>] [<outfile>]\n" "\n" ); REPORT_VERSION("ts2es"); print_msg( "\n" " Extract a single (elementary) program stream from a Transport Stream\n" " (or Program Stream).\n" "\n" "Files:\n" " <infile> is an H.222 Transport Stream file (but see -stdin and -pes)\n" " <outfile> is a single elementary stream file (but see -stdout)\n" "\n" "Which stream to extract:\n" " -pid <pid> Output data for the stream with the given\n" " <pid>. Use -pid 0x<pid> to specify a hex value\n" " -video Output data for the (first) video stream\n" " named in the (first) PMT. This is the default.\n" " -audio Output data for the (first) audio stream\n" " named in the (first) PMT\n" "\n" "General switches:\n" " -err stdout Write error messages to standard output (the default)\n" " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -stdout Output to standard output, instead of a file\n" " Forces -quiet and -err stderr.\n" " -verbose, -v Output informational/diagnostic messages\n" " -quiet, -q Only output error messages\n" " -max <n>, -m <n> Maximum number of TS packets to read\n" "\n" " -pes, -ps Use the PES interface to read ES units from\n" " the input file. This allows PS data to be read\n" " (there is no point in using this for TS data).\n" " Does not support -pid, -stdin or -stdout.\n" ); }
static void print_usage() { print_msg( "Usage: psdots [switches] [<infile>]\n" "\n" ); REPORT_VERSION("psdots"); print_msg( "\n" " Present the content of a Program Stream file as a sequence of\n" " characters, representing the packets.\n" "\n" "Files:\n" " <infile> is an H.222 Program Stream file (but see -stdin)\n" "\n" "Switches:\n" " -err stdout Write error messages to standard output (the default)\n" " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdin Input from standard input, instead of a file\n" " -verbose, -v Output a description of the characters used\n" " -max <n>, -m <n> Maximum number of PS packets to read\n" ); }
static void print_usage(void) { print_msg( "Usage: tsfilter [switches] <pid> <pid> <pid> ... \n" "\n"); REPORT_VERSION("tsfilter"); print_msg( "\n" " Filter the given pids out of stdin and write the result on stdout.\n" "\n" "Switches:\n" " -i <infile> Take input from this file and not stdin.\n" " -o <outfile> Send output to this file and not stdout.\n" " -verbose, -v Be verbose.\n" " -max <n>, -m <n> All packets after the nth are regarded as\n" " not matching any pids.\n" " -!, -invert Invert whatever your decision was before \n" " applying it - the output contains only \n" " pids not in the list up to max packets \n" " and all packets in the input from then \n" " on.\n" ); }
static void print_usage() { printf( "Usage: tsreport [switches] [<infile>] [switches]\n" "\n" ); REPORT_VERSION("tsreport"); printf( "\n" " Report on one of the following for the given Transport Stream:\n" "\n" " * The number of TS packets.\n" " * PCR and PTS/DTS differences (-buffering).\n" " * The packets of a single PID (-justpid).\n" "\n" " When conflicting switches are specified, the last takes effect.\n" "\n" "Input:\n" " <infile> Read data from the named H.222 Transport Stream file\n" " -stdin Read data from standard input\n" "\n" "Normal operation:\n" " By default, normal operation just reports the number of TS packets.\n" " -timing, -t Report timing information based on the PCRs.\n" " -data Show TS packet/payload data as bytes\n" " -verbose, -v Also output (fairly detailed) information on each TS packet.\n" " -quiet, -q Only output summary information (this is the default)\n" " -max <n>, -m <n> Maximum number of TS packets to read\n" "\n" "Buffering information:\n" " -buffering, -b Report on the differences between PCR and PTS, and\n" " between PCR and DTS. This is relevant to the size of\n" " buffers needed in the decoder.\n" " -o <file> Output CSV data for -buffering to the named file.\n" " -32 Truncate 33 bit values in the CSV output to 32 bits\n" " (losing the top bit).\n" " -verbose, -v Output PCR/PTS/DTS information as it is found (in a\n" " format similar to that used for -o)\n" " -quiet, -q Output less information (notably, not the PMT)\n" " -cnt <pid>, Check values of continuity_counter in the specified PID.\n" " Writes all the values of the counter to a file called\n" " 'continuity_counter.txt'. Turns buffering on (-b).\n" " -max <n>, -m <n> Maximum number of TS packets to read\n" "\n" "Single PID:\n" " -justpid <pid> Just show data (file offset, index, adaptation field\n" " and payload) for TS packets with the given PID.\n" " PID 0 is allowed (i.e., the PAT).\n" " -verbose, -v Is ignored\n" " -quiet, -q Is ignored\n" " -max <n>, -m <n> Maximum number of TS packets of that PID to read\n" "\n" "Experimental control of timestamp formats (this doesn't affect the output\n" "to the CVS file, produced with -o):\n" " -tfmt <thing> Specify format of time differences.\n" " -tafmt <thing> Specify format of absolute times.\n" "\n" " <thing> is (currently, but may change) one of:\n" " 90 Default -- show as 90KHz timestamps (suffix 't' on\n" " the values: e.g., 4362599t).\n" " 27 Show as 27MHz timestamps (similar, e.g., 25151:000t).\n" " 32 Show as 90KHz timestamps, but only the low 32 bits.\n" " ms Show as milliseconds.\n" " hms Show as hours/minutes/seconds (H:MM:SS.ssss, the H\n" " can be more than one digit if necessary)\n" ); }
/* ---------------------------------------------------------------- */ int main(int argc, char *argv[]) { /* ---------------------------------------------------------------- */ /* TODO waiting a better place */ /* PPTV */ char live_url[] = "http://web-play.pptv.com/web-m3u8-300164.m3u8"; //char live_url[] = "http://web-play.pptv.com/web-m3u8-300166.m3u8"; //char live_url[] = "http://web-play.pptv.com/web-m3u8-300169.m3u8"; /* -------------------------------------------------------------------------------------------------------------- */ /* next sohu */ //char live_url[] = "http://gslb.tv.sohu.com/live?cid=60&type=hls"; //char live_url[] = "http://gslb.tv.sohu.com/live?cid=59&type=hls"; //char live_url[] = "http://gslb.tv.sohu.com/live?cid=51&type=hls"; //char live_url[] = "http://gslb.tv.sohu.com/live?cid=53&type=hls"; //char live_url[] = "http://gslb.tv.sohu.com/live?cid=3&type=hls"; //dongfang weishi /* -------------------------------------------------------------------------------------------------------------- */ /* yangshi */ //char live_url[] = "http://t.live.cntv.cn/m3u8/cctv-4.m3u8"; //char live_url[] = "http://vdn.apps.cntv.cn/api/getLiveUrlCommonRedirectApi.do?channel=pa://cctv_p2p_hdcctv6&type=ipad"; //char live_url[] = "http://rtmp.cntv.lxdns.com/live/cctv-fengyunzuqiu/playlist.m3u8"; /* LETV */ //char live_url[] = "http://live.gslb.letv.com/gslb?stream_id=cctv9&tag=live&ext=m3u8&sign=live_ipad"; /* -------------------------------------------------------------------------------------------------------------- */ /* QQTV */ //char live_url[] = "http://zb.v.qq.com:1863/?progid=2084914015&ostype=ios"; //char live_url[] = "http://zb.v.qq.com:1863/?progid=2674956498&ostype=ios"; //jiangsu weishi 1 //char live_url[] = "http://zb.v.qq.com:1863/?progid=1258215255&ostype=ios"; //jiangsu weishi 2 //char live_url[] = "http://liveipad.wasu.cn/jsws_ipad/z.m3u8"; //jiangsu weishi 3 /* -------------------------------------------------------------------------------------------------------------- */ /* mix source */ //char live_url[] = "http://liveipad.wasu.cn/ahws_ipad/z.m3u8"; //char live_url[] = "http://live.gslb.letv.com/gslb?stream_id=dongnan&tag=live&ext=m3u8&sign=live_ipad"; //char live_url[] = "http://itv.hdpfans.com/live?vid=43"; /* not hls */ //char live_url[] = "http://live.gslb.letv.com/gslb?stream_id=hunan&tag=live&ext=m3u8&sign=live_ipad"; //char live_url[] = "http://114.112.34.103:82/live/5/45/3bde7498f8b64e738f7e5b4938415b3d.m3u"; //char live_url[] = "http://url.52itv.cn/live/70473843713237686132364D"; /* do not work ??? */ //char live_url[] = "http://114.112.34.103:82/live/5/45/cc535b8712c347ceb850ddd27ea60045.m3u"; //char live_url[] = "http://live1.ms.tvb.com/tvb/tv/jade/033.m3u8"; //char live_url[] = "http://live.gslb.letv.com/gslb?stream_id=bjkaku&tag=live&ext=m3u8&sign=live_ipad"; //char live_url[] = "http://live.gslb.letv.com/gslb?stream_id=btv6_800&tag=live&ext=m3u8"; /* -------------------------------------------------------------------------------------------------------------- */ /* CUTV */ //char live_url[] = "http://tsl2.hls.cutv.com/cutvChannelLive/2YeHjQB.m3u8"; /* this channel cause segment fault */ //char live_url[] = "http://tsl5.hls.cutv.com/cutvChannelLive/Qg929n9.m3u8"; /* some flv source */ //char live_url[] = "http://v4.cztv.com/channels/107/500.flv/live"; /* bug source test */ //char live_url[] = "http://114.112.34.103:82/live/5/45/3bde7498f8b64e738f7e5b4938415b3d.m3u"; /* -------------------------------------------------------------------------------------------------------------- */ REPORT_VERSION("httplive"); /* create a virtual network file livetv.ts */ char *file_name = "livetv.ts"; if (hls_create_virtual_file(file_name) != HLS_SUCCESS) goto fail1; /* -------------------------------------------------------------------------------------------------------------- */ /** * step 1 -> create hls_glb */ hls_obj_t *hls_obj = hls_mallocz(sizeof(hls_obj_t)); /* FIXME do not forget memory free */ if (hls_obj == NULL) { hls_err("malloc hls_hls_obj_t failed!\n"); return HLS_ERR; } hls_obj_fill(hls_obj); hls_obj->pre_hls_obj = NULL; pre_hls_obj = hls_obj; /* init some global structs and flags */ /* init libcurl */ curl_http_init(); sem_init(&proxy_start_sem, 0, 0); pthread_mutex_init(&active_live_th.mutex, NULL); /** * step 2 -> get url request */ /* put live_url to struct hls_glb */ hls_info("Playback ===> [%s]\n", live_url); hls_obj->live_url = live_url; /* create the hls m3u8 playlist parsing thread */ if (hls_create_thread(&hls_obj->th_hls_live, hls_obj, hls_live_thread) != HLS_SUCCESS) goto fail1; /** * step 3 -> start mongoose proxy */ /* create the hls mongoose server thread */ if (hls_create_thread(&th_hls_mongoose, hls_obj, hls_mongoose_thread) != HLS_SUCCESS) goto fail2; /** * ............................................... */ /* waiting here for TV channel change */ /* FIXME waiting for the hls_live_thread return, muse be current one, and will be * changed when new channel arrive * [may need an active thread_obj chain, and join in the for(;;)] */ /* do it first (because act_th->n_ths adds at the hls_live_thread func, sometimes main thread may * has been running here, but the hls_live_thread has not been running, n_ths is 0) */ hls_info(">>>>>>>>>>>>>>>>>>>pthread join [0]\n"); pthread_join(hls_obj->th_hls_live, NULL); /* then try again, and will be more, because of channel change */ pthread_list_join(&active_live_th); free_actth_list(&active_live_th); hls_info(">>>>>>>>>>>>>>>>>>>[waiting for mongoose thread] exit...\n"); /* TODO waiting for the hls_mongoose_thread return */ pthread_join(th_hls_mongoose, NULL); fail2: /* destroy some global flag */ sem_destroy(&proxy_start_sem); /* clean up libcurl */ curl_http_uninit(); pthread_mutex_destroy(&active_live_th.mutex); hls_info(">>>>>>>>>>>>>>>>>>>[main thread] exit...\n"); return HLS_SUCCESS; fail1: /* TODO */ return HLS_ERR; }
static void print_usage() { print_msg( "Usage: ps2ts [switches] [<infile>] [<outfile>]\n" "\n" ); REPORT_VERSION("ps2ts"); print_msg( "\n" " Convert an H.222 program stream to H.222 transport stream.\n" "\n" " This program does not make use of any Program Stream Map packets\n" " in the data (mainly because I have yet to see data with any). This\n" " means that the program has to determine the stream type of the data\n" " based on the first few ES units.\n" "\n" " This program does not output more than one video and one audio\n" " stream. If the program stream data contains more than one of each,\n" " the first will be used, and the others ignored (with a message\n" " indicating this).\n" "\n" " It is assumed that the video stream will contain DTS values in its\n" " PES packets at reasonable intervals, which can be used as PCR values\n" " in the transport stream, and thus the video stream's PID can be used\n" " as the PCR PID in the transport stream.\n" "\n" "Files:\n" " <infile> is a file containing the program stream data\n" " (but see -stdin below)\n" " <outfile> is a transport stream file\n" " (but see -stdout and -host below)\n" "\n" "Input switches:\n" " -stdin Take input from <stdin>, instead of a named file\n" " -dvd The PS data is from a DVD. This is the default.\n" " This switch has no effect on MPEG-1 PS data.\n" " -notdvd, -nodvd The PS data is not from a DVD.\n" " The DVD specification stores AC-3 (Dolby), DTS and\n" " other audio in a specialised manner in private_stream_1.\n" " -vstream <n> Take video from video stream <n> (0..7).\n" " The default is the first video stream found.\n" " -astream <n> Take audio from audio stream <n> (0..31).\n" " The default is the first audio stream found\n" " (this includes private_stream_1 on non-DVD streams).\n" " -ac3stream <n> Take audio from AC3 substream <n> (0..7), from\n" " private_stream_1. This implies -dvd.\n" " (If audio is being taken from a substream, the user\n" " is assumed to have determined which one is wanted,\n" " e.g., using psreport)\n" "\n" "Output switches:\n" " -err stdout Write error messages to standard output (the default)\n" " -err stderr Write error messages to standard error (Unix traditional)\n" " -stdout Write output to <stdout>, instead of a named file\n" " Forces -quiet and -err stderr.\n" " -host <host>, -host <host>:<port>\n" " Writes output (over TCP/IP) to the named <host>,\n" " instead of to a named file. If <port> is not\n" " specified, it defaults to 88.\n" " -vpid <pid> <pid> is the video PID to use for the data.\n" " Use '-vpid 0x<pid>' to specify a hex value.\n" " Defaults to 0x68.\n" " -apid <pid> <pid> is the audio PID to use for the data.\n" " Use '-apid 0x<pid>' to specify a hex value.\n" " Defaults to 0x67.\n" " -noaudio Don't output the audio data\n" " -pmt <pid> <pid> is the PMT PID to use.\n" " Use '-pmt 0x<pid>' to specify a hex value.\n" " Defaults to 0x66\n" " -prepeat <n> Output the program data (PAT/PMT) after every <n>\n" " PS packs. Defaults to 100.\n" " -pad <n> Pad the start with <n> filler TS packets, to allow\n" " a TS reader to synchronize with the datastream.\n" " Defaults to 8.\n" "\n" "General switches:\n" " -verbose, -v Print a 'v' for each video packet and an 'a' for \n" " each audio packet, as it is read\n" " -quiet, -q Only output error messages\n" " -max <n>, -m <n> Maximum number of PS packs to read\n" "\n" "Stream type:\n" " When the TS data is being output, it is flagged to indicate whether\n" " it conforms to H.262, H.264, etc. It is important to get this right, as\n" " it will affect interpretation of the TS data.\n" "\n" " If input is from a file, then the program will look at the start of\n" " the file to determine if the stream is H.264 or H.262 data. This\n" " process may occasionally come to the wrong conclusion, in which case\n" " the user can override the choice using the following switches.\n" "\n" " If input is from standard input (via -stdin), then it is not possible\n" " for the program to make its own decision on the input stream type.\n" " Instead, it defaults to H.262, and relies on the user indicating if\n" " this is wrong.\n" "\n" " -h264, -avc Force the program to treat the input as MPEG-4/AVC.\n" " -h262 Force the program to treat the input as MPEG-2.\n" " -mp42 Force the program to treat the input as MPEG-4/Part 2.\n" " -vtype <type> Force the program to treat the input as video of\n" " stream type <type> (e.g., 0x42 means AVS video). It is\n" " up to the user to specify a valid <type>.\n" "\n" " If the audio stream being output is Dolby (AC-3), then the stream type\n" " used to output it differs for DVB (European) and ATSC (USA) data. It\n" " may be specified as follows:\n" "\n" " -dolby dvb Use stream type 0x06 (the default)\n" " -dolby atsc Use stream type 0x81\n" ); }