Пример #1
0
int CMp4File::create_text(CPlayerSession *psptr, 
			   text_query_t *tq, 
			   uint text_offset,
			   uint &start_desc)
{
  uint ix;
  //uint64_t IVLength;
  CPlayerMedia *mptr;
  codec_plugin_t *plugin;
  uint32_t verb = MP4GetVerbosity(m_mp4file);
  for (ix = 0; ix < text_offset; ix++) {
    if (tq[ix].enabled != 0) {
      CMp4TextByteStream *tbyte;
      mptr = new CPlayerMedia(psptr, TIMED_TEXT_SYNC);
      if (mptr == NULL) {
	return (-1);
      }

      /* check if ismacryp */
#if 0
      uint32_t verb = MP4GetVerbosity(m_mp4file);
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      if (MP4IsIsmaCrypMediaTrack(m_mp4file, aq[ix].track_id)) {
        IVLength = MP4GetTrackIntegerProperty(m_mp4file,
                    aq[ix].track_id, "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.IV-length");
	abyte = new CMp4EncAudioByteStream(this, aq[ix].track_id, IVLength);
      } else {
	abyte = new CMp4AudioByteStream(this, aq[ix].track_id);
      }
      MP4SetVerbosity(m_mp4file, verb);
#else
      tbyte = new CMp4TextByteStream(this, tq[ix].track_id);
#endif

      int ret;
      plugin = check_for_text_codec(tq[ix].stream_type,
				    tq[ix].compressor,
				    NULL,
				    NULL,
				    0, 
				    &config);

      ret = mptr->create_text_plugin(plugin,
				     STREAM_TYPE_MP4_FILE,
				     tq[ix].compressor,
				     NULL, // sdp info
				     NULL, 
				     0);
      if (ret < 0) {
	mp4f_message(LOG_ERR, "Couldn't create text from plugin %s", 
		     plugin->c_name);
	psptr->set_message("Couldn't start text plugin %s", 
			   plugin->c_name);
	delete mptr;
	delete tbyte;
	return -1;
      }

      ret = mptr->create_media("text", tbyte);
      if (ret != 0) {
	return (-1);
      }
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      char *mp4info = MP4Info(m_mp4file, tq[ix].track_id);
      MP4SetVerbosity(m_mp4file, verb);
      char *temp = mp4info;
      while (*temp != '\0') {
	if (isspace(*temp)) *temp = ' ';
	if (!isprint(*temp)) *temp = '*';
	temp++;
      }
      psptr->set_session_desc(start_desc, mp4info);
      free(mp4info);
      start_desc++;
    } else {
      CHECK_AND_FREE(tq[ix].config);
    }
  }

  return 0;
}
Пример #2
0
int CMp4File::create_video(CPlayerSession *psptr, 
			   video_query_t *vq, 
			   uint video_offset,
			   uint &start_desc)
{
  uint ix;
  CPlayerMedia *mptr;
  codec_plugin_t *plugin;

  for (ix = 0; ix < video_offset; ix++) {
    if (vq[ix].enabled != 0) {

      mptr = new CPlayerMedia(psptr, VIDEO_SYNC);
      if (mptr == NULL) {
	return (-1);
      }
						  
      video_info_t *vinfo;
      vinfo = (video_info_t *)malloc(sizeof(video_info_t));
      vinfo->height = vq[ix].h;
      vinfo->width = vq[ix].w;
      plugin = check_for_video_codec(vq[ix].stream_type,
				     vq[ix].compressor,
				     NULL,
				     vq[ix].type,
				     vq[ix].profile,
				     vq[ix].config, 
				     vq[ix].config_len,
				     &config);

      int ret = mptr->create_video_plugin(plugin, 
					  vq[ix].stream_type,
					  vq[ix].compressor,
					  vq[ix].type,
					  vq[ix].profile,
					  NULL, // sdp info
					  vinfo, // video info
					  vq[ix].config,
					  vq[ix].config_len);

      if (ret < 0) {
	mp4f_message(LOG_ERR, "Failed to create plugin data");
	psptr->set_message("Failed to start plugin");
	delete mptr;
	return -1;
      }

      CMp4VideoByteStream *vbyte;
      uint64_t IVLength;
     
      /* check if ismacryp */
      uint32_t verb = MP4GetVerbosity(m_mp4file);
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      if (strcasecmp(vq[ix].compressor, "avc1") == 0) {
	vbyte = new CMp4H264VideoByteStream(this, vq[ix].track_id);
      } else if (strcasecmp(vq[ix].compressor, "encv") == 0) {
        MP4GetTrackIntegerProperty(m_mp4file,
				   vq[ix].track_id, 
				   "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.IV-length", 
				   &IVLength);
	vbyte = new CMp4EncVideoByteStream(this, vq[ix].track_id,IVLength);
      } else {
	vbyte = new CMp4VideoByteStream(this, vq[ix].track_id);
      }
      MP4SetVerbosity(m_mp4file, verb);

      if (vbyte == NULL) {
	delete mptr;
	return (-1);
      }

      ret = mptr->create_media("video", vbyte);
      if (ret != 0) {
	return (-1);
      }
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      char *mp4info = MP4Info(m_mp4file, vq[ix].track_id);
      MP4SetVerbosity(m_mp4file, verb);
      char *temp = mp4info;
      while (*temp != '\0') {
	if (isspace(*temp)) *temp = ' ';
	if (!isprint(*temp)) *temp = '*';
	temp++;
      }
      psptr->set_session_desc(start_desc, mp4info);
      free(mp4info);
      start_desc++;
    } else {
      if (vq[ix].config != NULL) free((void *)vq[ix].config);
    }
  }
  return 0;
}
Пример #3
0
int CMp4File::create_audio(CPlayerSession *psptr, 
			   audio_query_t *aq, 
			   uint audio_offset,
			   uint &start_desc)
{
  uint ix;
  uint64_t IVLength;
  CPlayerMedia *mptr;
  codec_plugin_t *plugin;
  for (ix = 0; ix < audio_offset; ix++) {
    if (aq[ix].enabled != 0) {
      CMp4AudioByteStream *abyte;
      mptr = new CPlayerMedia(psptr, AUDIO_SYNC);
      if (mptr == NULL) {
	return (-1);
      }

      /* check if ismacryp */
      uint32_t verb = MP4GetVerbosity(m_mp4file);
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      if (MP4IsIsmaCrypMediaTrack(m_mp4file, aq[ix].track_id)) {
        MP4GetTrackIntegerProperty(m_mp4file,
                    aq[ix].track_id, "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.IV-length", &IVLength);
	abyte = new CMp4EncAudioByteStream(this, aq[ix].track_id, IVLength);
      } else {
	abyte = new CMp4AudioByteStream(this, aq[ix].track_id);
      }
      MP4SetVerbosity(m_mp4file, verb);

      audio_info_t *ainfo;
      ainfo = (audio_info_t *)malloc(sizeof(audio_info_t));
      memset(ainfo, 0, sizeof(*ainfo));

      ainfo->freq = aq[ix].sampling_freq;
      if (aq[ix].chans != -1) {
	ainfo->chans = aq[ix].chans;
      }
      if ((aq[ix].type == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE) ||
	  (aq[ix].type == MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE)) {
	ainfo->bitspersample = 16;
      }

      int ret;
      plugin = check_for_audio_codec(STREAM_TYPE_MP4_FILE,
				     aq[ix].compressor, // media_data field
				     NULL,
				     aq[ix].type,
				     aq[ix].profile,
				     aq[ix].config,
				     aq[ix].config_len,
				     &config);

      ret = mptr->create_audio_plugin(plugin,
				      STREAM_TYPE_MP4_FILE,
				      aq[ix].compressor,
				      aq[ix].type, 
				      aq[ix].profile,
				      NULL, // sdp info
				      ainfo, // audio info
				      aq[ix].config,
				      aq[ix].config_len);
      if (ret < 0) {
	mp4f_message(LOG_ERR, "Couldn't create audio from plugin %s", 
		     plugin->c_name);
	psptr->set_message("Couldn't start audio plugin %s", 
			   plugin->c_name);
	delete mptr;
	delete abyte;
	return -1;
      }

      ret = mptr->create_media("audio", abyte);
      if (ret != 0) {
	return (-1);
      }
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      char *mp4info = MP4Info(m_mp4file, aq[ix].track_id);
      MP4SetVerbosity(m_mp4file, verb);
      char *temp = mp4info;
      while (*temp != '\0') {
	if (isspace(*temp)) *temp = ' ';
	if (!isprint(*temp)) *temp = '*';
	temp++;
      }
      psptr->set_session_desc(start_desc, mp4info);
      free(mp4info);
      start_desc++;
    } else {
      if (aq[ix].config != NULL) free((void *)aq[ix].config);
    }
  }

  return 0;
}
Пример #4
0
int CMp4File::create_video(CPlayerSession *psptr, 
			   video_query_t *vq, 
			   uint video_offset,
			   uint &start_desc)
{
  uint ix;
  CPlayerMedia *mptr;
  codec_plugin_t *plugin;
  const char *file_kms_uri;
  const char *inuse_kms_uri;

  for (ix = 0; ix < video_offset; ix++) {
    if (vq[ix].enabled != 0) {

      mptr = new CPlayerMedia(psptr, VIDEO_SYNC);
      if (mptr == NULL) {
	return (-1);
      }
						  
      video_info_t *vinfo;
      vinfo = (video_info_t *)malloc(sizeof(video_info_t));
      vinfo->height = vq[ix].h;
      vinfo->width = vq[ix].w;
      plugin = check_for_video_codec(vq[ix].stream_type,
				     vq[ix].compressor,
				     NULL,
				     vq[ix].type,
				     vq[ix].profile,
				     vq[ix].config, 
				     vq[ix].config_len,
				     &config);

      int ret = mptr->create_video_plugin(plugin, 
					  vq[ix].stream_type,
					  vq[ix].compressor,
					  vq[ix].type,
					  vq[ix].profile,
					  NULL, // sdp info
					  vinfo, // video info
					  vq[ix].config,
					  vq[ix].config_len);

      if (ret < 0) {
	mp4f_message(LOG_ERR, "Failed to create plugin data");
	psptr->set_message("Failed to start plugin");
	delete mptr;
	return -1;
      }

      CMp4VideoByteStream *vbyte = NULL;
      uint64_t IVLength;
     
      /* check if clear-text or ismacryp.
       * in this context original format is encv 
       * and compressor specifies which codec
       */
      uint32_t verb = MP4GetVerbosity(m_mp4file);
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      if (strcasecmp(vq[ix].original_fmt, "avc1") == 0) {
	vbyte = new CMp4H264VideoByteStream(this, vq[ix].track_id);
      } else if (strcasecmp(vq[ix].original_fmt, "encv") == 0) {
        MP4GetTrackIntegerProperty(m_mp4file,
				   vq[ix].track_id, 
				   "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.IV-length", 
				   &IVLength);

      	if (strcasecmp(vq[ix].compressor, "mp4v") == 0) {
	vbyte = new CMp4EncVideoByteStream(this, vq[ix].track_id,IVLength);
	}
      	else if (((strcasecmp(vq[ix].compressor, "avc1") == 0) 
      	|| (strcasecmp(vq[ix].compressor, "264b")) == 0)) {
		vbyte = new CMp4EncH264VideoByteStream(this, vq[ix].track_id,IVLength);

		// check if file kms uri matches in-use kms uri
		// advisory only 
		MP4GetTrackStringProperty(m_mp4file, vq[ix].track_id, 
			"mdia.minf.stbl.stsd.encv.sinf.schi.iKMS.kms_URI", 
			&file_kms_uri);
		inuse_kms_uri = 
			((CMp4EncH264VideoByteStream *)vbyte)->get_inuse_kms_uri();
		if (file_kms_uri && inuse_kms_uri) {
			if (strcmp(file_kms_uri, inuse_kms_uri)) {
				mp4f_message(LOG_DEBUG, 
				"KMS in file (%s) does not match KMS in use (%s)\n", 
				file_kms_uri, inuse_kms_uri);
      		}
		}
	}
      } else {
	vbyte = new CMp4VideoByteStream(this, vq[ix].track_id);
      }
      MP4SetVerbosity(m_mp4file, verb);

      if (vbyte == NULL) {
	delete mptr;
	return (-1);
      }

      ret = mptr->create_media("video", vbyte);
      if (ret != 0) {
	return (-1);
      }
      MP4SetVerbosity(m_mp4file, verb & ~(MP4_DETAILS_ERROR));
      char *mp4info = MP4Info(m_mp4file, vq[ix].track_id);
      MP4SetVerbosity(m_mp4file, verb);
      char *temp = mp4info;
      while (*temp != '\0') {
	if (isspace(*temp)) *temp = ' ';
	if (!isprint(*temp)) *temp = '*';
	temp++;
      }
      psptr->set_session_desc(start_desc, mp4info);
      free(mp4info);
      start_desc++;
    } else {
      if (vq[ix].config != NULL) free((void *)vq[ix].config);
    }
  }
  return 0;
}
Пример #5
0
static int create_mpeg3_video (video_query_t *vq,
                               mpeg2ps_t *vfile,
                               CPlayerSession *psptr,
                               int &sdesc)
{
    CPlayerMedia *mptr;
    codec_plugin_t *plugin;
    int ret;

    plugin = check_for_video_codec(STREAM_TYPE_MPEG_FILE,
                                   "mp2v",
                                   NULL,
                                   vq->type,
                                   -1,
                                   NULL,
                                   0,
                                   &config);
    if (plugin == NULL) {
        psptr->set_message("Can't find plugin for mpeg video");
        return 0;
    }
    mptr = new CPlayerMedia(psptr, VIDEO_SYNC);
    if (mptr == NULL) {
        psptr->set_message("Could not create video media");
        return -1;
    }
    video_info_t *vinfo;
    vinfo = MALLOC_STRUCTURE(video_info_t);
    vinfo->height = vq->h;
    vinfo->width = vq->w;

    char buffer[80];
    int bitrate;
    char *name = mpeg2ps_get_video_stream_name(vfile, vq->track_id);
    ret = snprintf(buffer, 80, "%s Video, %d x %d",
                   name,
                   vinfo->width, vinfo->height);
    free(name);
    if (vq->frame_rate != 0.0) {
        ret += snprintf(buffer + ret, 80 - ret, ", %g", vq->frame_rate);
    }
    bitrate =
        (int)(mpeg2ps_get_video_stream_bitrate(vfile, vq->track_id) / 1000.0);
    if (bitrate > 0) {
        snprintf(buffer + ret, 80 - ret, ", %d kbps", bitrate);
    }
    psptr->set_session_desc(sdesc, buffer);
    sdesc++;
    mpeg3f_message(LOG_DEBUG, "video stream h %d w %d fr %g bitr %d",
                   vinfo->height, vinfo->width, vq->frame_rate,
                   bitrate);
    ret = mptr->create_video_plugin(plugin, STREAM_TYPE_MPEG_FILE,
                                    vq->compressor,
                                    vq->type, vq->profile,
                                    NULL, vinfo, NULL, 0);
    if (ret < 0) {
        mpeg3f_message(LOG_ERR, "Failed to create video plugin");
        psptr->set_message("Failed to create video plugin");
        free(vinfo);
        return -1;
    }
    CMpeg3VideoByteStream *vbyte;
    vbyte = new CMpeg3VideoByteStream(vfile, vq->track_id);
    if (vbyte == NULL) {
        psptr->set_message("Failed to create video bytestream");
        return -1;
    }
    ret = mptr->create_media("video", vbyte);
    if (ret != 0) {
        psptr->set_message("Couldn't create video media");
        return -1;
    }
    return 1;
}
Пример #6
0
static int create_mpeg3_audio (audio_query_t * aq,
                               mpeg2ps_t *afile,
                               CPlayerSession *psptr,
                               int &sdesc)
{
    CPlayerMedia *mptr;
    codec_plugin_t *plugin;
    int ret;

    plugin = check_for_audio_codec(STREAM_TYPE_MPEG_FILE,
                                   NULL,
                                   NULL,
                                   aq->type,
                                   -1,
                                   NULL,
                                   0,
                                   &config);
    if (plugin == NULL) {
        psptr->set_message("Can't find plugin for mpeg audio format %s",
                           mpeg2ps_get_audio_stream_name(afile, aq->track_id));
        return 0;
    }
    mptr = new CPlayerMedia(psptr, AUDIO_SYNC);
    if (mptr == NULL) {
        psptr->set_message("Could not create video media");
        return -1;
    }
    audio_info_t *ainfo;
    ainfo = MALLOC_STRUCTURE(audio_info_t);
    ainfo->freq = aq->sampling_freq;
    ainfo->chans = aq->chans;
    ainfo->bitspersample = 16;

    char buffer[80];
    snprintf(buffer, 80, "%s Audio, %d, %d channels",
             mpeg2ps_get_audio_stream_name(afile, aq->track_id),
             ainfo->freq,
             ainfo->chans);
    psptr->set_session_desc(sdesc, buffer);
    sdesc++;

    ret = mptr->create_audio_plugin(plugin, aq->stream_type,
                                    aq->compressor,
                                    aq->type, aq->profile,
                                    NULL, ainfo, NULL, 0);
    if (ret < 0) {
        mpeg3f_message(LOG_ERR, "Failed to create audio plugin");
        psptr->set_message("Failed to create audio plugin");
        free(ainfo);
        delete mptr;
        return -1;
    }
    CMpeg3AudioByteStream *abyte;
    abyte = new CMpeg3AudioByteStream(afile, aq->track_id);
    if (abyte == NULL) {
        psptr->set_message("Failed to create audio bytestream");
        return -1;
    }
    ret = mptr->create_media("audio", abyte);
    if (ret != 0) {
        psptr->set_message("Couldn't create audio media");
        return -1;
    }
    return 1;
}
Пример #7
0
int CMpeg2tFile::create_audio (CPlayerSession *psptr,
			       mpeg2t_t *decoder,
			       audio_query_t *aq,
			       uint audio_offset,
			       int &sdesc)
{
  uint ix;
  CPlayerMedia *mptr;
  codec_plugin_t *plugin;
  int created = 0;

  for (ix = 0; ix < audio_offset; ix++) {
    mpeg2t_pid_t *pidptr;
    mpeg2t_es_t *es_pid;
    pidptr = mpeg2t_lookup_pid(decoder,aq[ix].track_id);
    if (pidptr->pak_type != MPEG2T_ES_PAK) {
      mpeg2f_message(LOG_CRIT, "mpeg2t video type is not es pak - pid %x",
		     aq[ix].track_id);
      exit(1);
    }
    es_pid = (mpeg2t_es_t *)pidptr;
    if (aq[ix].enabled != 0 && created == 0) {
      created = 1;
      mptr = new CPlayerMedia(psptr, AUDIO_SYNC);
      if (mptr == NULL) {
	return (-1);
      }
      audio_info_t *ainfo;
      ainfo = MALLOC_STRUCTURE(audio_info_t);
      ainfo->freq = aq[ix].sampling_freq;
      ainfo->chans = aq[ix].chans;
      ainfo->bitspersample = 0;
      plugin = check_for_audio_codec(STREAM_TYPE_MPEG2_TRANSPORT_STREAM,
				     NULL,
				     NULL,
				     aq[ix].type,
				     aq[ix].profile,
				     aq[ix].config, 
				     aq[ix].config_len,
				     &config);

      int ret = mptr->create_audio_plugin(plugin, 
					  STREAM_TYPE_MPEG2_TRANSPORT_STREAM,
					  NULL,
					  aq[ix].type,
					  aq[ix].profile,
					  NULL, // sdp info
					  ainfo, // video info
					  aq[ix].config,
					  aq[ix].config_len);

      if (ret < 0) {
	mpeg2f_message(LOG_ERR, "Failed to create plugin data");
	psptr->set_message("Failed to start plugin");
	delete mptr;
	return -1;
      }

      CMpeg2fAudioByteStream *abyte;
      abyte = new CMpeg2fAudioByteStream(this, es_pid);
      if (abyte == NULL) {
	mpeg2f_message(LOG_CRIT, "failed to create byte stream");
	delete mptr;
	return (-1);
      }
      ret = mptr->create_media("audio", abyte, false);
      if (ret != 0) {
	mpeg2f_message(LOG_CRIT, "failed to create from file");
	return (-1);
      }
      if (es_pid->info_loaded) {
	char buffer[80];
	if (mpeg2t_write_stream_info(es_pid, buffer, 80) >= 0) {
	  psptr->set_session_desc(sdesc, buffer);
	  sdesc++;
	}
      }
      mpeg2t_set_frame_status(es_pid, MPEG2T_PID_SAVE_FRAME);
    }  else {
      mpeg2t_set_frame_status(es_pid, MPEG2T_PID_NOTHING);
    }
  }
  return created;
}
Пример #8
0
int CMpeg2tFile::create_video (CPlayerSession *psptr,
			       mpeg2t_t *decoder,
			       video_query_t *vq,
			       uint video_offset,
			       int &sdesc)
{
  uint ix;
  CPlayerMedia *mptr;
  codec_plugin_t *plugin;
  int created = 0;

  // Loop through the vq structure, and set up a new player media
  for (ix = 0; ix < video_offset; ix++) {
    mpeg2t_pid_t *pidptr;
    mpeg2t_es_t *es_pid;
    pidptr = mpeg2t_lookup_pid(decoder,vq[ix].track_id);
    if (pidptr->pak_type != MPEG2T_ES_PAK) {
      mpeg2f_message(LOG_CRIT, "mpeg2t video type is not es pak - pid %x",
		     vq[ix].track_id);
      exit(1);
    }
    es_pid = (mpeg2t_es_t *)pidptr;
    if (vq[ix].enabled != 0 && created == 0) {
      created = 1;
      mptr = new CPlayerMedia(psptr, VIDEO_SYNC);
      if (mptr == NULL) {
	return (-1);
      }
      video_info_t *vinfo;
      vinfo = MALLOC_STRUCTURE(video_info_t);
      vinfo->height = vq[ix].h;
      vinfo->width = vq[ix].w;
      plugin = check_for_video_codec(STREAM_TYPE_MPEG2_TRANSPORT_STREAM,
				     NULL,
				     NULL,
				     vq[ix].type,
				     vq[ix].profile,
				     vq[ix].config, 
				     vq[ix].config_len,
				     &config);

      int ret = mptr->create_video_plugin(plugin, 
					  STREAM_TYPE_MPEG2_TRANSPORT_STREAM,
					  NULL,
					  vq[ix].type,
					  vq[ix].profile,
					  NULL, // sdp info
					  vinfo, // video info
					  vq[ix].config,
					  vq[ix].config_len);

      if (ret < 0) {
	mpeg2f_message(LOG_ERR, "Failed to create plugin data");
	psptr->set_message("Failed to start plugin");
	delete mptr;
	return -1;
      }

      CMpeg2fVideoByteStream *vbyte;
      vbyte = new CMpeg2fVideoByteStream(this, es_pid);
      if (vbyte == NULL) {
	mpeg2f_message(LOG_CRIT, "failed to create byte stream");
	delete mptr;
	return (-1);
      }
      ret = mptr->create_media("video", vbyte, false);
      if (ret != 0) {
	mpeg2f_message(LOG_CRIT, "failed to create from file");
	return (-1);
      }
      if (es_pid->info_loaded) {
	char buffer[80];
	if (mpeg2t_write_stream_info(es_pid, buffer, 80) >= 0) {
	  psptr->set_session_desc(sdesc, buffer);
	  sdesc++;
	}
      }
      mpeg2t_set_frame_status(es_pid, MPEG2T_PID_SAVE_FRAME);
    }  else {
      mpeg2t_set_frame_status(es_pid, MPEG2T_PID_NOTHING);
    }
  }
  return created;
}