Beispiel #1
0
static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
    lavf_priv_t *priv= demuxer->priv;
    AVStream *st= avfc->streams[i];
    AVCodecContext *codec= st->codec;
    char *stream_type = NULL;
    int stream_id;
    AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
    AVDictionaryEntry *title= av_dict_get(st->metadata, "title",    NULL, 0);
    int g;

    switch(codec->codec_type){
        case AVMEDIA_TYPE_AUDIO:{
            WAVEFORMATEX *wf;
            sh_audio_t* sh_audio;
            sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams, lang ? lang->value : NULL);
            if(!sh_audio)
                break;
            stream_type = "audio";
            priv->astreams[priv->audio_streams] = i;
            wf= calloc(sizeof(*wf) + codec->extradata_size, 1);
            codec->codec_tag = mp_codec_id2tag(codec->codec_id, codec->codec_tag, 1);
            wf->wFormatTag= codec->codec_tag;
            wf->nChannels= codec->channels;
            wf->nSamplesPerSec= codec->sample_rate;
            wf->nAvgBytesPerSec= codec->bit_rate/8;
            wf->nBlockAlign= codec->block_align ? codec->block_align : 1;
            wf->wBitsPerSample= codec->bits_per_coded_sample;
            wf->cbSize= codec->extradata_size;
            if(codec->extradata_size)
                memcpy(wf + 1, codec->extradata, codec->extradata_size);
            sh_audio->wf= wf;
            sh_audio->audio.dwSampleSize= codec->block_align;
            if(codec->frame_size && codec->sample_rate){
                sh_audio->audio.dwScale=codec->frame_size;
                sh_audio->audio.dwRate= codec->sample_rate;
            }else{
                sh_audio->audio.dwScale= codec->block_align ? codec->block_align*8 : 8;
                sh_audio->audio.dwRate = codec->bit_rate;
            }
            g= av_gcd(sh_audio->audio.dwScale, sh_audio->audio.dwRate);
            sh_audio->audio.dwScale /= g;
            sh_audio->audio.dwRate  /= g;
//          printf("sca:%d rat:%d fs:%d sr:%d ba:%d\n", sh_audio->audio.dwScale, sh_audio->audio.dwRate, codec->frame_size, codec->sample_rate, codec->block_align);
            sh_audio->ds= demuxer->audio;
            sh_audio->format= codec->codec_tag;
            sh_audio->channels= codec->channels;
            sh_audio->samplerate= codec->sample_rate;
            sh_audio->i_bps= codec->bit_rate/8;
            switch (codec->codec_id) {
                case CODEC_ID_PCM_S8:
                case CODEC_ID_PCM_U8:
                    sh_audio->samplesize = 1;
                    break;
                case CODEC_ID_PCM_S16LE:
                case CODEC_ID_PCM_S16BE:
                case CODEC_ID_PCM_U16LE:
                case CODEC_ID_PCM_U16BE:
                    sh_audio->samplesize = 2;
                    break;
                case CODEC_ID_PCM_ALAW:
                    sh_audio->format = 0x6;
                    break;
                case CODEC_ID_PCM_MULAW:
                    sh_audio->format = 0x7;
                    break;
            }
            if (title && title->value)
                mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", priv->audio_streams, title->value);
            if (st->disposition & AV_DISPOSITION_DEFAULT)
              sh_audio->default_track = 1;
            if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
            // select the first audio stream if auto-selection is requested
            if (demuxer->audio->id == -1) {
                demuxer->audio->id = i;
                demuxer->audio->sh= demuxer->a_streams[i];
            }
            if (demuxer->audio->id != i)
                st->discard= AVDISCARD_ALL;
            stream_id = priv->audio_streams++;
            break;
        }
        case AVMEDIA_TYPE_VIDEO:{
            sh_video_t* sh_video;
            BITMAPINFOHEADER *bih;
            sh_video=new_sh_video_vid(demuxer, i, priv->video_streams);
            if(!sh_video) break;
            stream_type = "video";
            priv->vstreams[priv->video_streams] = i;
            bih=calloc(sizeof(*bih) + codec->extradata_size,1);

            if(codec->codec_id == CODEC_ID_RAWVIDEO) {
                switch (codec->pix_fmt) {
                    case PIX_FMT_RGB24:
                        codec->codec_tag= MKTAG(24, 'B', 'G', 'R');
                    case PIX_FMT_BGR24:
                        codec->codec_tag= MKTAG(24, 'R', 'G', 'B');
                }
            }
            codec->codec_tag = mp_codec_id2tag(codec->codec_id, codec->codec_tag, 0);
            bih->biSize= sizeof(*bih) + codec->extradata_size;
            bih->biWidth= codec->width;
            bih->biHeight= codec->height;
            bih->biBitCount= codec->bits_per_coded_sample;
            bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount/8;
            bih->biCompression= codec->codec_tag;
            sh_video->bih= bih;
            sh_video->disp_w= codec->width;
            sh_video->disp_h= codec->height;
            if (st->time_base.den) { /* if container has time_base, use that */
                sh_video->video.dwRate= st->time_base.den;
                sh_video->video.dwScale= st->time_base.num;
            } else {
                sh_video->video.dwRate= codec->time_base.den;
                sh_video->video.dwScale= codec->time_base.num;
            }
            sh_video->fps=av_q2d(st->r_frame_rate);
            sh_video->frametime=1/av_q2d(st->r_frame_rate);
            sh_video->format=bih->biCompression;
            if(st->sample_aspect_ratio.num)
                sh_video->aspect = codec->width  * st->sample_aspect_ratio.num
                         / (float)(codec->height * st->sample_aspect_ratio.den);
            else
                sh_video->aspect=codec->width  * codec->sample_aspect_ratio.num
                       / (float)(codec->height * codec->sample_aspect_ratio.den);
            sh_video->i_bps=codec->bit_rate/8;
            if (title && title->value)
                mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n", priv->video_streams, title->value);
            mp_msg(MSGT_DEMUX,MSGL_DBG2,"aspect= %d*%d/(%d*%d)\n",
                codec->width, codec->sample_aspect_ratio.num,
                codec->height, codec->sample_aspect_ratio.den);

            sh_video->ds= demuxer->video;
            if(codec->extradata_size)
                memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size);
            if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh_video->bih, MSGL_V);
            /*
                short biPlanes;
                int  biXPelsPerMeter;
                int  biYPelsPerMeter;
                int biClrUsed;
                int biClrImportant;
            */
            // select the first video stream if auto-selection is requested
            if(demuxer->video->id == -1) {
                demuxer->video->id = i;
                demuxer->video->sh= demuxer->v_streams[i];
            }
            if(demuxer->video->id != i)
                st->discard= AVDISCARD_ALL;
            stream_id = priv->video_streams++;
            break;
        }
        case AVMEDIA_TYPE_SUBTITLE:{
            sh_sub_t* sh_sub;
            char type;
            if(codec->codec_id == CODEC_ID_TEXT ||
               codec->codec_id == AV_CODEC_ID_SUBRIP)
                type = 't';
            else if(codec->codec_id == CODEC_ID_MOV_TEXT)
                type = 'm';
            else if(codec->codec_id == CODEC_ID_SSA)
                type = 'a';
            else if(codec->codec_id == CODEC_ID_DVD_SUBTITLE)
                type = 'v';
            else if(codec->codec_id == CODEC_ID_XSUB)
                type = 'x';
            else if(codec->codec_id == CODEC_ID_DVB_SUBTITLE)
                type = 'b';
            else if(codec->codec_id == CODEC_ID_DVB_TELETEXT)
                type = 'd';
            else if(codec->codec_id == CODEC_ID_HDMV_PGS_SUBTITLE)
                type = 'p';
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 14, 100)
            else if(codec->codec_id == CODEC_ID_EIA_608)
                type = 'c';
#endif
            else if(codec->codec_tag == MKTAG('c', '6', '0', '8'))
                type = 'c';
            else
                break;
            sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams, lang ? lang->value : NULL);
            if(!sh_sub) break;
            stream_type = "subtitle";
            priv->sstreams[priv->sub_streams] = i;
            sh_sub->type = type;
            if (codec->extradata_size) {
                sh_sub->extradata = malloc(codec->extradata_size);
                memcpy(sh_sub->extradata, codec->extradata, codec->extradata_size);
                sh_sub->extradata_len = codec->extradata_size;
            }
            if (title && title->value)
                mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n", priv->sub_streams, title->value);
            if (st->disposition & AV_DISPOSITION_DEFAULT)
              sh_sub->default_track = 1;
            stream_id = priv->sub_streams++;
            break;
        }
        case AVMEDIA_TYPE_ATTACHMENT:{
            if (st->codec->codec_id == CODEC_ID_TTF) {
                AVDictionaryEntry *fnametag = av_dict_get(st->metadata, "filename", NULL, 0);
                demuxer_add_attachment(demuxer, fnametag ? fnametag->value : NULL,
                                       "application/x-truetype-font",
                                       codec->extradata, codec->extradata_size);
            }
            break;
        }
        default:
            st->discard= AVDISCARD_ALL;
    }
    if (stream_type) {
        AVCodec *avc = avcodec_find_decoder(codec->codec_id);
        const char *codec_name = avc ? avc->name : "unknown";
        if (!avc && *stream_type == 's' && demuxer->s_streams[i])
            codec_name = sh_sub_type2str(((sh_sub_t *)demuxer->s_streams[i])->type);
        mp_msg(MSGT_DEMUX, MSGL_INFO, "[lavf] stream %d: %s (%s), -%cid %d", i, stream_type, codec_name, *stream_type, stream_id);
        if (lang && lang->value && *stream_type != 'v')
            mp_msg(MSGT_DEMUX, MSGL_INFO, ", -%clang %s", *stream_type, lang->value);
        if (title && title->value)
            mp_msg(MSGT_DEMUX, MSGL_INFO, ", %s", title->value);
        mp_msg(MSGT_DEMUX, MSGL_INFO, "\n");
    }
}
static demuxer_t *demux_isdbt_open(demuxer_t * demuxer)
{
	sh_video_t *shv;
	sh_audio_t *sha;
	char* filename;
	int 	ret;
	int 	resolution, samplefreq;

	LOGE("demux_isdbt_open in\n");
	//	char audio_context[20] = {0x2b,0x10,0x88,0x00};
	//	char audio_context[20] = {0x11,0x90,};
	/* Fix me lator BTLSYS */
//#if DEF_ISDBT_AACV2	/* Brazil */
//	LOGE("[ISDBT_DEMUX] OPEN in AACv2 Brazil version\n");
//	char audio_context[4] = {0xeb,0x09,0x88,0x00};	//Audio object type :AAC LC(Low complexity)
//#else
//	LOGE("[ISDBT_DEMUX] OPEN in AAC Japan version\n");
//	char audio_context[4] = {0x13,0x10,0x88,0x00};
//#endif
	char audio_AACV2_context[4] = {0xeb,0x09,0x88,0x00};
	char audio_AAC_context[4] = {0x13,0x10,0x88,0x00};
	//char audio_context[20] = {0x16,0x10,0x88,0x00};
	//char audio_context[20] = {0xeb,0x09,0x88,0x00};	//Audio object type :AAC LC(Low complexity)

	//uint8_t vcodecinfo[] = {0x00, 0x00, 0x01, 0x67, 0x42, 0xe0, 0x0d, 0x96, 0x52, 0x02, 0x83, 0xf4, 0x90, 0x08, 0x00, 0x00, 0x01, 0x68, 0xce, 0x38, 0x80};
	uint8_t vcodecinfo[] = {0x00, 0x00, 0x01, 0x67, 0x42, 0xe0, 0x0d, 0x99, 0xa0, 0x68, 0x7e, 0xc0, 0x5a, 0x83, 0x03, 0x03, 0x78, 0x00, 0x00, 0x1f, 0x48, 0x00, 0x07, 0x53, 0x04, 0x00, 0x00, 0x01, 0x68, 0xce, 0x3c, 0x80};
	//	demuxer->video->id =-2;
	//	LOGE("DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n",
	//	   demuxer->audio->id, demuxer->video->id, demuxer->sub->id);

	mp_msg(MSGT_DEMUX, MSGL_V, "DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n",
		   demuxer->audio->id, demuxer->video->id, demuxer->sub->id);
	demuxer->type= DEMUXER_TYPE_ISDBT;
	demuxer->file_format= DEMUXER_TYPE_ISDBT;
	//	stream_reset(demuxer->stream);
	filename=demuxer->filename;
	if( strncmp(filename, "mtv:", strlen("mtv:") ) == 0 )
	  LOGE("file name is :%s \n",filename);
	LOGE("demux_isdbt_open in111 %s\n",demuxer->filename);

	mFreq = 0;
	mFreq = GetIntValue( filename, "freq" ); 
	if( mFreq <= 0 )
	  LOGE("error get freq!\n");
	else
	  LOGE("get freq is : %d\n",mFreq );

	mChannel = 0;
	mChannel =GetIntValue(filename, "channel");
	if( mChannel < 0 )
	  LOGE("error get channel num!\n");
	else
	  LOGE("get channel num is : %d\n",mChannel);


	demuxer->seekable = 0;

	/* 5 th try */
	for (int i=0 ; i < 5 ; i++)
	{
		ret = isdbt_tv_set_channel(mFreq,mChannel);
		LOGE("demux_isdbt_open() ret %d", ret);
		if (ret == 0)
			break;
	}

	if (ret != 0)
		return NULL;

	resolution = samplefreq = 0;
	isdbt_getStreamInfo(&resolution, &samplefreq);

	if (samplefreq < 10)
	{
		isAudioTypeAACV2 = 0;	//AAC
	}
	else  
	{
		isAudioTypeAACV2 = 1;	//AACV2
		samplefreq -= 10;
	}

	if (samplefreq < 0 || resolution > 7)
		samplefreq = 6;

	if (resolution != 0 && resolution != 1)
		resolution = 0;

	if (isAudioTypeAACV2)
		LOGE("isdbt_getStreamInfo() AACV2 resolution %d , samplefreq %d", resolution , samplefreq);
	else
		LOGE("isdbt_getStreamInfo() AAC resolution %d , samplefreq %d", resolution , samplefreq);		

#if 1
	sha = new_sh_audio_aid(demuxer, 1, 64,NULL);

	if(sha)
	{
	      sha->format = AUDIO_AAC;
	      sha->ds = demuxer->audio;

			if (samplefreq == 3) 
				sha->samplerate = 48000;
			else if (samplefreq == 4) 
				sha->samplerate = 44100;
			else if (samplefreq == 5) 
				sha->samplerate = 32000;
			else if (samplefreq == 6) 
				sha->samplerate = 24000;
			else if (samplefreq == 8) 
				sha->samplerate = 16000;
			else
			    sha->samplerate = 24000;

		  LOGE("[Demux Open] Audio SampleFreq %d\n",sha->samplerate);

		  //sha->samplerate = 44100;	//testing
		/** In case Japan ISDBT AAC , Not setting is more stable 
               	 **/
		if (isAudioTypeAACV2)
		{
		      sha->samplesize = 2;
		      sha->channels = 2;
	
		      //sha->i_bps = 96*1000/8;		//120326 Audio bps 96k
		
		  //sha->channels = 0;			//testing 
		      sha->wf = (WAVEFORMATEX *) malloc(sizeof (WAVEFORMATEX) + 4);
		      sha->wf->cbSize = 4;
		      sha->wf->nChannels = 2;
		  //sha->wf->nChannels = 0;		//testing 
	
//		  if (isAudioTypeAACV2)
//		      memcpy(sha->wf + 1, audio_AACV2_context, 4);
//		  else
		      memcpy(sha->wf + 1, audio_AAC_context, 4);			
		}
		
	      	demuxer->audio->id = 64;
	      	sha->ds = demuxer->audio;
	      	demuxer->audio->sh = sha;
	}
#endif
#if 1
	shv = new_sh_video_vid(demuxer, 0, 80);
	if(shv)
	{

	      shv->format = VIDEO_AVC;
		  //shv->format = VIDEO_H264;	
	      shv->ds = demuxer->video;
	      shv->bih = (BITMAPINFOHEADER *) calloc(1, sizeof(BITMAPINFOHEADER) + 25);
	      shv->bih->biSize= sizeof(BITMAPINFOHEADER);

		  // BTL , 110308 --> no meaning
#if 0
		  shv->fps=24; // we probably won't even care about fps
		  shv->frametime = 1.0f/shv->fps;
#endif
	      shv->bih->biWidth = 320;		// no video display
		  //shv->bih->biWidth = 416;	
	      //shv->bih->biHeight = 240;
		  if (resolution == 1)
		  	shv->bih->biHeight = 240;
		  else
			shv->bih->biHeight = 180;

		  LOGE("[Demux Open] Video Resolution (320 x %d)\n",shv->bih->biHeight);
	      demuxer->video->id = 80;
	      shv->ds = demuxer->video;
	      demuxer->video->sh = shv;
	}
#endif
	demuxer->movi_start = 0;


#if 0	//AAC channel config = 0 problem patch testing 
    if(!sha->codecdata_len){
      sha->a_in_buffer_size=6144;
      sha->a_in_buffer = av_mallocz(sha->a_in_buffer_size);
      //sha->a_in_buffer_len = demux_read_data(sha->ds, sha->a_in_buffer, sha->a_in_buffer_size);
	  sha->a_in_buffer_len = isdbt_get_audio_first_frame(sha->a_in_buffer, sha->a_in_buffer_size);
      //demux_seek(demuxer,demuxer->movi_start,0,SEEK_ABSOLUTE);
    }
#endif
	return demuxer;
}
static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
    lavf_priv_t *priv= demuxer->priv;
    AVStream *st= avfc->streams[i];
    AVCodecContext *codec= st->codec;
    char *stream_type = NULL;
    int stream_id;
    AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL, 0);
    AVMetadataTag *title= av_metadata_get(st->metadata, "title",    NULL, 0);
    int g, override_tag = av_codec_get_tag(mp_codecid_override_taglists,
                                           codec->codec_id);
    // For some formats (like PCM) always trust CODEC_ID_* more than codec_tag
    if (override_tag)
        codec->codec_tag = override_tag;

    switch(codec->codec_type){
        case CODEC_TYPE_AUDIO:{
            WAVEFORMATEX *wf;
            sh_audio_t* sh_audio;
            sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams, lang ? lang->value : NULL);
            if(!sh_audio)
                break;
            stream_type = "audio";
            priv->astreams[priv->audio_streams] = i;
            wf= calloc(sizeof(WAVEFORMATEX) + codec->extradata_size, 1);
            // mp4a tag is used for all mp4 files no matter what they actually contain
            if(codec->codec_tag == MKTAG('m', 'p', '4', 'a'))
                codec->codec_tag= 0;
            if(!codec->codec_tag)
                codec->codec_tag= av_codec_get_tag(mp_wav_taglists, codec->codec_id);
            wf->wFormatTag= codec->codec_tag;
            wf->nChannels= codec->channels;
            wf->nSamplesPerSec= codec->sample_rate;
            wf->nAvgBytesPerSec= codec->bit_rate/8;
            wf->nBlockAlign= codec->block_align ? codec->block_align : 1;
            wf->wBitsPerSample= codec->bits_per_coded_sample;
            wf->cbSize= codec->extradata_size;
            if(codec->extradata_size)
                memcpy(wf + 1, codec->extradata, codec->extradata_size);
            sh_audio->wf= wf;
            sh_audio->audio.dwSampleSize= codec->block_align;
            if(codec->frame_size && codec->sample_rate){
                sh_audio->audio.dwScale=codec->frame_size;
                sh_audio->audio.dwRate= codec->sample_rate;
            }else{
                sh_audio->audio.dwScale= codec->block_align ? codec->block_align*8 : 8;
                sh_audio->audio.dwRate = codec->bit_rate;
            }
            g= av_gcd(sh_audio->audio.dwScale, sh_audio->audio.dwRate);

            sh_audio->audio.dwScale /= g;
            sh_audio->audio.dwRate  /= g;
//          printf("sca:%d rat:%d fs:%d sr:%d ba:%d\n", sh_audio->audio.dwScale, sh_audio->audio.dwRate, codec->frame_size, codec->sample_rate, codec->block_align);
            sh_audio->ds= demuxer->audio;
            sh_audio->format= codec->codec_tag;
            sh_audio->channels= codec->channels;
            sh_audio->samplerate= codec->sample_rate;
            /*
	      in opencore : 
              try_decode_frame() delete in libavformat/utils.c ,so some parame maybe not be get 
	      so if samplerate no get in header, then give a fix value 44100
	    */
	    if(!sh_audio->channels)
		sh_audio->channels = 2;
	    if(!sh_audio->samplerate)
		sh_audio->samplerate = 44100;

            sh_audio->i_bps= codec->bit_rate/8;
            switch (codec->codec_id) {
                case CODEC_ID_PCM_S8:
                case CODEC_ID_PCM_U8:
                    sh_audio->samplesize = 1;
                    break;
                case CODEC_ID_PCM_S16LE:
                case CODEC_ID_PCM_S16BE:
                case CODEC_ID_PCM_U16LE:
                case CODEC_ID_PCM_U16BE:
                    sh_audio->samplesize = 2;
                    break;
                case CODEC_ID_PCM_ALAW:
                    sh_audio->format = 0x6;
                    break;
                case CODEC_ID_PCM_MULAW:
                    sh_audio->format = 0x7;
                    break;
            }
            if (title && title->value)
                mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", priv->audio_streams, title->value);
            if (st->disposition & AV_DISPOSITION_DEFAULT)
              sh_audio->default_track = 1;
            if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
            // select the first audio stream
            if (!demuxer->audio->sh) {
                demuxer->audio->id = i;
                demuxer->audio->sh= demuxer->a_streams[i];
            } else
	        st->discard= AVDISCARD_ALL;
            stream_id = priv->audio_streams++;
            break;
        }
        case CODEC_TYPE_VIDEO:{
            sh_video_t* sh_video;
            BITMAPINFOHEADER *bih;
            sh_video=new_sh_video_vid(demuxer, i, priv->video_streams);
            if(!sh_video) break;
            stream_type = "video";
            priv->vstreams[priv->video_streams] = i;
            bih=calloc(sizeof(BITMAPINFOHEADER) + codec->extradata_size,1);

            if(codec->codec_id == CODEC_ID_RAWVIDEO) {
                switch (codec->pix_fmt) {
                    case PIX_FMT_RGB24:
                        codec->codec_tag= MKTAG(24, 'B', 'G', 'R');
                }
            }
            if(!codec->codec_tag)
                codec->codec_tag= av_codec_get_tag(mp_bmp_taglists, codec->codec_id);
            bih->biSize= sizeof(BITMAPINFOHEADER) + codec->extradata_size;
	    if(!codec->width || !codec->height){
	      codec->width = 16*4;	    
	      codec->height = 9*4;
	    }
            bih->biWidth= codec->width;
            bih->biHeight= codec->height;
            bih->biBitCount= codec->bits_per_coded_sample;
            bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount/8;
            bih->biCompression= codec->codec_tag;
            sh_video->bih= bih;
            sh_video->disp_w= codec->width;
            sh_video->disp_h= codec->height;
            if (st->time_base.den) { /* if container has time_base, use that */
                sh_video->video.dwRate= st->time_base.den;
                sh_video->video.dwScale= st->time_base.num;
            } else {
                sh_video->video.dwRate= codec->time_base.den;
                sh_video->video.dwScale= codec->time_base.num;
            }
            sh_video->fps=av_q2d(st->r_frame_rate);
            sh_video->frametime=1/av_q2d(st->r_frame_rate);
            sh_video->format=bih->biCompression;
            if(st->sample_aspect_ratio.num)
                sh_video->aspect = codec->width  * st->sample_aspect_ratio.num
                         / (float)(codec->height * st->sample_aspect_ratio.den);
            else
                sh_video->aspect=codec->width  * codec->sample_aspect_ratio.num
                       / (float)(codec->height * codec->sample_aspect_ratio.den);
	    sh_video->rotation_degrees = st->rotation_degrees;
            sh_video->i_bps=codec->bit_rate/8;
            if (title && title->value)
                mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n", priv->video_streams, title->value);
            mp_msg(MSGT_DEMUX,MSGL_DBG2,"aspect= %d*%d/(%d*%d)\n",
                codec->width, codec->sample_aspect_ratio.num,
                codec->height, codec->sample_aspect_ratio.den);

            sh_video->ds= demuxer->video;
            if(codec->extradata_size)
                memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size);
            if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh_video->bih, MSGL_V);
            /*
                short biPlanes;
                int  biXPelsPerMeter;
                int  biYPelsPerMeter;
                int biClrUsed;
                int biClrImportant;
            */
            if(demuxer->video->id != i && demuxer->video->id != -1)
                st->discard= AVDISCARD_ALL;
            else{
                demuxer->video->id = i;
                demuxer->video->sh= demuxer->v_streams[i];
            }
            stream_id = priv->video_streams++;
            break;
        }
        case CODEC_TYPE_SUBTITLE:{
            sh_sub_t* sh_sub;
            char type;
            /* only support text subtitles for now */
            if(codec->codec_id == CODEC_ID_TEXT)
                type = 't';
            else if(codec->codec_id == CODEC_ID_MOV_TEXT)
                type = 'm';
            else if(codec->codec_id == CODEC_ID_SSA)
                type = 'a';
            else if(codec->codec_id == CODEC_ID_DVD_SUBTITLE)
                type = 'v';
            else if(codec->codec_id == CODEC_ID_XSUB)
                type = 'x';
            else if(codec->codec_id == CODEC_ID_DVB_SUBTITLE)
                type = 'b';
            else if(codec->codec_id == CODEC_ID_DVB_TELETEXT)
                type = 'd';
            else if(codec->codec_id == CODEC_ID_HDMV_PGS_SUBTITLE)
                type = 'p';
            else
                break;
            sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams, lang ? lang->value : NULL);
            if(!sh_sub) break;
            stream_type = "subtitle";
            priv->sstreams[priv->sub_streams] = i;
            sh_sub->type = type;
            if (codec->extradata_size) {
                sh_sub->extradata = malloc(codec->extradata_size);
                memcpy(sh_sub->extradata, codec->extradata, codec->extradata_size);
                sh_sub->extradata_len = codec->extradata_size;
            }
            if (title && title->value)
                mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n", priv->sub_streams, title->value);
            if (st->disposition & AV_DISPOSITION_DEFAULT)
              sh_sub->default_track = 1;
            stream_id = priv->sub_streams++;
            break;
        }
        case CODEC_TYPE_ATTACHMENT:{
            if (st->codec->codec_id == CODEC_ID_TTF)
                demuxer_add_attachment(demuxer, st->filename,
                                       "application/x-truetype-font",
                                       codec->extradata, codec->extradata_size);
            break;
        }
        default:
            st->discard= AVDISCARD_ALL;
    }
    if (stream_type) {
        AVCodec *avc = avcodec_find_decoder(codec->codec_id);
        const char *codec_name = avc ? avc->name : "unknown";
	if (strcmp("tta", codec_name) == 0)
	  demuxer->ttaflag = 1;
        if (!avc && *stream_type == 's' && demuxer->s_streams[stream_id])
            codec_name = sh_sub_type2str(((sh_sub_t *)demuxer->s_streams[stream_id])->type);
        mp_msg(MSGT_DEMUX, MSGL_INFO, "[lavf] stream %d: %s (%s), -%cid %d", i, stream_type, codec_name, *stream_type, stream_id);
        if (lang && lang->value && *stream_type != 'v')
            mp_msg(MSGT_DEMUX, MSGL_INFO, ", -%clang %s", *stream_type, lang->value);
        if (title && title->value)
            mp_msg(MSGT_DEMUX, MSGL_INFO, ", %s", title->value);
        mp_msg(MSGT_DEMUX, MSGL_INFO, "\n");
    }
}
static demuxer_t *demux_isdbt_open(demuxer_t * demuxer)
{
	sh_video_t *shv;
	sh_audio_t *sha;
	char* filename;
	int 	ret;

	LOGE("demux_isdbt_open in\n");
	//	char audio_context[20] = {0x2b,0x10,0x88,0x00};
	//	char audio_context[20] = {0x11,0x90,};
	/* Fix me lator BTLSYS */
	char audio_context[20] = {0x13,0x10,0x88,0x00};	//48k
	//char audio_context[20] = {0x16,0x10,0x88,0x00};	//24k
	//char audio_context[20] = {0xeb,0x09,0x88,0x00};	//Audio object type :AAC LC(Low complexity)

	//uint8_t vcodecinfo[] = {0x00, 0x00, 0x01, 0x67, 0x42, 0xe0, 0x0d, 0x96, 0x52, 0x02, 0x83, 0xf4, 0x90, 0x08, 0x00, 0x00, 0x01, 0x68, 0xce, 0x38, 0x80};
	uint8_t vcodecinfo[] = {0x00, 0x00, 0x01, 0x67, 0x42, 0xe0, 0x0d, 0x99, 0xa0, 0x68, 0x7e, 0xc0, 0x5a, 0x83, 0x03, 0x03, 0x78, 0x00, 0x00, 0x1f, 0x48, 0x00, 0x07, 0x53, 0x04, 0x00, 0x00, 0x01, 0x68, 0xce, 0x3c, 0x80};
	//	demuxer->video->id =-2;
	//	LOGE("DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n",
	//	   demuxer->audio->id, demuxer->video->id, demuxer->sub->id);

	mp_msg(MSGT_DEMUX, MSGL_V, "DEMUX OPEN, AUDIO_ID: %d, VIDEO_ID: %d, SUBTITLE_ID: %d,\n",
		   demuxer->audio->id, demuxer->video->id, demuxer->sub->id);
	demuxer->type= DEMUXER_TYPE_ISDBT;
	demuxer->file_format= DEMUXER_TYPE_ISDBT;
	//	stream_reset(demuxer->stream);
	filename=demuxer->filename;
	if( strncmp(filename, "mtv:", strlen("mtv:") ) == 0 )
	  LOGE("file name is :%s \n",filename);
	LOGE("demux_isdbt_open in111 %s\n",demuxer->filename);

	mFreq = 0;
	mFreq = GetIntValue( filename, "freq" ); 
	if( mFreq <= 0 )
	  LOGE("error get freq!\n");
	else
	  LOGE("get freq is : %d\n",mFreq );

	mChannel = 0;
	mChannel =GetIntValue(filename, "channel");
	if( mChannel < 0 )
	  LOGE("error get channel num!\n");
	else
	  LOGE("get channel num is : %d\n",mChannel);


	demuxer->seekable = 0;
#if 1
	LOGE("demux_isdbt_open in222\n");
	sha = new_sh_audio_aid(demuxer, 1, 64,NULL);
	LOGE("demux_isdbt_open in333\n");
	if(sha)
	{
	      sha->format = AUDIO_AAC;
	      sha->ds = demuxer->audio;
	      sha->samplerate = 24000;
		  //sha->samplerate = 48000;	
	      sha->samplesize = 2;
	      sha->channels = 2;
#if 1
	      sha->wf = (WAVEFORMATEX *) malloc(sizeof (WAVEFORMATEX) + 4);
	      sha->wf->cbSize = 4;
	      sha->wf->nChannels = 2;
	      memcpy(sha->wf + 1, audio_context, 4);
#else

	      sha->wf = (WAVEFORMATEX *) malloc(sizeof (WAVEFORMATEX) + 2);
	      sha->wf->cbSize = 2;
	      memcpy(sha->wf + 1, audio_context, 2);
#endif

	      demuxer->audio->id = 64;
	      sha->ds = demuxer->audio;
	      demuxer->audio->sh = sha;
	}
#endif
#if 1
	shv = new_sh_video_vid(demuxer, 0, 80);
	if(shv)
	{

	      shv->format = VIDEO_AVC;
		  //shv->format = VIDEO_H264;	
	      shv->ds = demuxer->video;
	      shv->bih = (BITMAPINFOHEADER *) calloc(1, sizeof(BITMAPINFOHEADER) + 25);
	      shv->bih->biSize= sizeof(BITMAPINFOHEADER);

		  // BTL , 110308 --> no meaning
#if 0
		  shv->fps=24; // we probably won't even care about fps
		  shv->frametime = 1.0f/shv->fps;
#endif
	      shv->bih->biWidth = 320;		// no video display
		  //shv->bih->biWidth = 416;	
	      //shv->bih->biHeight = 240;
		  shv->bih->biHeight = 180;
	
	      demuxer->video->id = 80;
	      shv->ds = demuxer->video;
	      demuxer->video->sh = shv;
	}
#endif
	demuxer->movi_start = 0;

	/* 5 th try */
	for (int i=0 ; i < 5 ; i++)
	{
		ret = isdbt_tv_set_channel(mFreq,mChannel);
		LOGE("demux_isdbt_open() ret %d", ret);
		if (ret == 0)
			break;
	}
	if (ret != 0)
		return NULL;
	//isdbt_get_video_data_buffer(demuxer->video);
#if 0 //dmesg
	set_watch((void *)&demuxer->v_streams[47]);
#endif

	//	LOGE("demux_isdbt_open out");
	return demuxer;
}
Beispiel #5
0
static demuxer_t* demux_dshow_open (demuxer_t *demuxer)
{
	sh_video_t *sh_video;
	sh_audio_t *sh_audio;
	stream_pos = 0;
	last_vpts = 0;
	b_stopped = 0;
	b_vfinished = 0;
	b_afinished = 0;
	b_firstframe = 1;
	b_firstaframe = 1;
	g_vpkg.pData = NULL;
	g_apkg.pData = NULL;
	apkg_buf = NULL;
	apkg_buf_size = 0;

	if(AudioInfo.demuxer)
		demux_info_add(demuxer, "DShow Demuxer", AudioInfo.demuxer);

	if(VideoInfo.haveVideo) {
		if (VideoInfo.avgtimeperframe < 10000)
			VideoInfo.avgtimeperframe = 400000;

		sh_video = new_sh_video(demuxer, 0);

		if (demuxer->video->id == -1) demuxer->video->id = 0;
		if (demuxer->video->id == 0)
		demuxer->video->sh = sh_video;
		sh_video->ds = demuxer->video;

		sh_video->disp_w = VideoInfo.width;
		sh_video->disp_h = VideoInfo.height;
		sh_video->format = mmioFOURCC('Y', 'V', '1', '2');

		sh_video->frametime = (float)(VideoInfo.avgtimeperframe/1E7);
		sh_video->fps = 1.0 / sh_video->frametime;

		sh_video->bih = calloc (1, sizeof (BITMAPINFOHEADER));
		sh_video->bih->biSize = sizeof (BITMAPINFOHEADER);
		sh_video->bih->biWidth = VideoInfo.width;
		sh_video->bih->biHeight = VideoInfo.height;
		sh_video->bih->biBitCount = 12;
		sh_video->bih->biSizeImage = sh_video->bih->biWidth * sh_video->bih->biHeight * sh_video->bih->biBitCount/8;
		sh_video->bih->biCompression = sh_video->format;
		if(VideoInfo.videoDecoder)
			demux_info_add(demuxer, "DShow Video", VideoInfo.videoDecoder);

		if(VideoInfo.aspectX > 1 && VideoInfo.aspectY > 1)
			sh_video->aspect = (float)VideoInfo.width*(float)VideoInfo.aspectX/((float)VideoInfo.height*(float)VideoInfo.aspectY);
	}

	if(AudioInfo.haveAudio) {
		sh_audio = new_sh_audio_aid(demuxer, 0, 0, NULL);
		demuxer->audio->id = 0;
		demuxer->audio->sh = sh_audio;
		sh_audio->ds = demuxer->audio;
		sh_audio->wf = malloc (sizeof (WAVEFORMATEX));
		memset(sh_audio->wf, 0, sizeof (WAVEFORMATEX));

		if(AudioInfo.audioDecoder) {
			if(AudioInfo.wFormatTag == 0xfffe && !strcmp(AudioInfo.audioDecoder, "Microsoft DTV-DVD Audio Decoder"))
				AudioInfo.wFormatTag = 0x3;
			demux_info_add(demuxer, "DShow Audio", AudioInfo.audioDecoder);
		}
		sh_audio->format = sh_audio->wf->wFormatTag = AudioInfo.wFormatTag;
		sh_audio->channels = sh_audio->wf->nChannels = AudioInfo.nChannels;
		sh_audio->samplerate = sh_audio->wf->nSamplesPerSec = AudioInfo.nSamplesPerSec;
		sh_audio->wf->wBitsPerSample = AudioInfo.wBitsPerSample;
		sh_audio->wf->nBlockAlign = sh_audio->channels * sh_audio->wf->wBitsPerSample / 8;
		sh_audio->wf->nAvgBytesPerSec = sh_audio->wf->nBlockAlign * sh_audio->samplerate;
        sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec;

	}

	duration = GetGraphDuration(g_pdgi);

	hWaitVSend = CreateEventA(NULL, FALSE, FALSE, NULL);
	hWaitASend = CreateEventA(NULL, FALSE, FALSE, NULL);
	hWaitVDec = CreateEventA(NULL, FALSE, FALSE, NULL);
	hWaitADec = CreateEventA(NULL, FALSE, FALSE, NULL);

	StartGraph(g_pdgi);

    return demuxer;
}