コード例 #1
0
ファイル: avi_file.cpp プロジェクト: acassis/emlinux-ssd1935
/*
 * Create the media for the quicktime file, and set up some session stuff.
 */
int create_media_for_avi_file (CPlayerSession *psptr, 
			       const char *name,
			       char *errmsg,
			       uint32_t errlen,
			       int have_audio_driver,
			       control_callback_vft_t *cc_vft)
{
  CAviFile *Avifile1 = NULL;
  avi_t *avi;
  CPlayerMedia *mptr;
  avi = AVI_open_input_file(name, 1);
  if (avi == NULL) {
    snprintf(errmsg, errlen, "%s", AVI_strerror());
    player_error_message("%s", AVI_strerror());
    return (-1);
  }

  int video_count = 1;
  codec_plugin_t *plugin;
  video_query_t vq;

  const char *codec_name = AVI_video_compressor(avi);
  player_debug_message("Trying avi video codec %s", codec_name);
  plugin = check_for_video_codec(STREAM_TYPE_AVI_FILE,
				 codec_name, 
				 NULL,
				 -1,
				 -1,
				 NULL,
				 0, 
				 &config);
  if (plugin == NULL) {
    video_count = 0;
  } else {
    vq.track_id = 1;
    vq.stream_type = STREAM_TYPE_AVI_FILE;
    vq.compressor = codec_name;
    vq.type = -1;
    vq.profile = -1;
    vq.fptr = NULL;
    vq.h = AVI_video_height(avi);
    vq.w = AVI_video_width(avi);
    vq.frame_rate = AVI_video_frame_rate(avi);
    vq.config = NULL;
    vq.config_len = 0;
    vq.enabled = 0;
    vq.reference = NULL;
  }

  int have_audio = 0;
  int audio_count = 0;
  audio_query_t aq;

  if (AVI_audio_bytes(avi) != 0) {
    have_audio = 1;
    plugin = check_for_audio_codec(STREAM_TYPE_AVI_FILE,
				   NULL,
				   NULL,
				   AVI_audio_format(avi), 
				   -1, 
				   NULL, 
				   0,
				   &config);
    if (plugin != NULL) {
      audio_count = 1;
      aq.track_id = 1;
      aq.stream_type = STREAM_TYPE_AVI_FILE;
      aq.compressor = NULL;
      aq.type = AVI_audio_format(avi);
      aq.profile = -1;
      aq.fptr = NULL;
      aq.sampling_freq = AVI_audio_rate(avi);
      aq.chans = AVI_audio_channels(avi);
      aq.config = NULL;
      aq.config_len = 0;
      aq.enabled = 0;
      aq.reference = NULL;
    }
  }

  if (cc_vft != NULL && cc_vft->media_list_query != NULL) {
    (cc_vft->media_list_query)(psptr, video_count, &vq, audio_count, &aq);
  } else {
    if (video_count != 0) vq.enabled = 1;
    if (audio_count != 0) aq.enabled = 1;
  }


  if ((video_count == 0 || vq.enabled == 0) && 
      (audio_count == 0 || aq.enabled == 0)) {
    snprintf(errmsg, errlen, "No audio or video tracks enabled or playable");
    AVI_close(avi);
    return -1;
  }
  
  Avifile1 = new CAviFile(name, avi, vq.enabled, audio_count);
  psptr->set_media_close_callback(close_avi_file, Avifile1);

  if (video_count != 0 && vq.enabled) {
    mptr = new CPlayerMedia(psptr);
    if (mptr == NULL) {
      return (-1);
    }
  
    video_info_t *vinfo = MALLOC_STRUCTURE(video_info_t);
    if (vinfo == NULL) 
      return (-1);
    vinfo->height = vq.h;
    vinfo->width = vq.w;
    player_debug_message("avi file h %d w %d frame rate %g", 
			 vinfo->height,
			 vinfo->width,
			 vq.frame_rate);

    plugin = check_for_video_codec(STREAM_TYPE_AVI_FILE,
				   codec_name, 
				   NULL,
				   -1,
				   -1,
				   NULL,
				   0,
				   &config);
    int ret;
    ret = mptr->create_video_plugin(plugin,
				    STREAM_TYPE_AVI_FILE,
				    codec_name,
				    -1,
				    -1,
				    NULL,
				    vinfo,
				    NULL,
				    0);
    if (ret < 0) {
      snprintf(errmsg, errlen, "Failed to create video plugin %s", 
	       codec_name);
      player_error_message("Failed to create plugin data");
      delete mptr;
      return -1;
    }
    CAviVideoByteStream *vbyte = new CAviVideoByteStream(Avifile1);
    if (vbyte == NULL) {
      delete mptr;
      return (-1);
    }
    vbyte->config(AVI_video_frames(avi), vq.frame_rate);
    ret = mptr->create(vbyte, TRUE, errmsg, errlen);
    if (ret != 0) {
      return (-1);
    }
  }
    
  int seekable = 1;
  if (have_audio_driver > 0 && audio_count > 0 && aq.enabled != 0) {
    plugin = check_for_audio_codec(STREAM_TYPE_AVI_FILE,
				   NULL,
				   NULL,
				   aq.type,
				   -1, 
				   NULL, 
				   0,
				   &config);
    CAviAudioByteStream *abyte;
    mptr = new CPlayerMedia(psptr);
    if (mptr == NULL) {
      return (-1);
    }
    audio_info_t *ainfo;
    ainfo = MALLOC_STRUCTURE(audio_info_t);
    ainfo->freq = aq.sampling_freq;
    ainfo->chans = aq.chans;
    ainfo->bitspersample = AVI_audio_bits(avi); 

  
    int ret;
    ret = mptr->create_audio_plugin(plugin, 
				    aq.stream_type,
				    aq.compressor,
				    aq.type,
				    aq.profile,
				    NULL, 
				    ainfo,
				    NULL, 
				    0);
    if (ret < 0) {
      delete mptr;
      player_error_message("Couldn't create audio from plugin %s", 
			   plugin->c_name);
      return -1;
    }
    abyte = new CAviAudioByteStream(Avifile1);

    ret = mptr->create(abyte, FALSE, errmsg, errlen);
    if (ret != 0) {
      return (-1);
    }
    seekable = 0;
  } 
  psptr->session_set_seekable(seekable);

  if (audio_count == 0 && have_audio != 0) {
    snprintf(errmsg, errlen, "Unknown Audio Codec in avi file ");
    return (1);
  }
  if (video_count != 1) {
    snprintf(errmsg, errlen, "Unknown Video Codec %s in avi file",
	     codec_name);
    return (1);
  }
  return (0);
}
コード例 #2
0
int parse_name_for_session (CPlayerSession *psptr,
                            const char *name,
                            char *errmsg,
                            uint32_t errlen,
                            control_callback_vft_t *cc_vft)
{
    int err;
#ifdef HAVE_IGMP_V3
    //  gross, but here for multiple files
    const char *mcast_src = config.get_config_string(CONFIG_MULTICAST_SRC);
    if (mcast_src != NULL) {
        udp_set_multicast_src(mcast_src);
    } else {
        udp_set_multicast_src("0.0.0.0");
    }
#endif

    ADV_SPACE(name);
    if (strncmp(name, "rtsp://", strlen("rtsp://")) == 0) {
        err = create_media_for_streaming_ondemand(psptr,
                name,
                errmsg,
                errlen,
                cc_vft);
        return (err);
    }
    if (strncmp(name, "http://", strlen("http://")) == 0) {
        err = create_media_for_http(psptr, name, errmsg, errlen, cc_vft);
        return (err);
    }

    int have_audio_driver;

    have_audio_driver = do_we_have_audio();
#ifndef _WIN32
    if (strncmp(name, "iptv://", strlen("iptv://")) == 0) {
        err = create_media_for_iptv(psptr,
                                    name,
                                    errmsg,
                                    errlen,
                                    have_audio_driver,
                                    cc_vft);
        return err;
    }
#endif
#ifndef _WIN32
    if (strncmp(name, "mpeg2t://", strlen("mpeg2t://")) == 0) {
        err = create_mpeg2t_session(psptr, name, NULL, errmsg, errlen,
                                    have_audio_driver, cc_vft);
        return (err);
    }

    struct stat statbuf;
    if (stat(name, &statbuf) != 0) {
        snprintf(errmsg, errlen, "File \'%s\' not found", name);
        return (-1);
    }
    if (!S_ISREG(statbuf.st_mode)) {
        snprintf(errmsg, errlen, "File \'%s\' is not a file", name);
        return (-1);
    }
#else
    OFSTRUCT ReOpenBuff;
    if (OpenFile(name, &ReOpenBuff,OF_READ) == HFILE_ERROR) {
        snprintf(errmsg, errlen, "File %s not found", name);
        return (-1);
    }

#endif
    err = -1;

    const char *suffix = strrchr(name, '.');
    if (suffix == NULL) {
        snprintf(errmsg, errlen, "No useable suffix on file %s", name);
        return err;
    }


    if (strcasecmp(suffix, ".sdp") == 0) {
        err = create_media_from_sdp_file(psptr,
                                         name,
                                         errmsg,
                                         errlen,
                                         have_audio_driver,
                                         cc_vft);
    } else if ((strcasecmp(suffix, ".mov") == 0) ||
               (strcasecmp(suffix, ".mp4") == 0) ||
               (strcasecmp(suffix, ".3gp") == 0) ||
               (strcasecmp(suffix, ".m4a") == 0)) {
        if (config.get_config_value(CONFIG_USE_OLD_MP4_LIB) == 0) {
            err = create_media_for_mp4_file(psptr,
                                            name,
                                            errmsg,
                                            errlen,
                                            have_audio_driver,
                                            cc_vft);
        } else err = -1;
        if (err < 0) {
            err = create_media_for_qtime_file(psptr,
                                              name,
                                              errmsg,
                                              errlen,
                                              have_audio_driver);
        }
    } else if (strcasecmp(suffix, ".avi") == 0) {
        err = create_media_for_avi_file(psptr,
                                        name,
                                        errmsg,
                                        errlen,
                                        have_audio_driver,
                                        cc_vft);
    } else if (strcasecmp(suffix, ".mpeg") == 0 ||
               strcasecmp(suffix, ".mpg") == 0 ||
               strcasecmp(suffix, ".vob") == 0) {
#ifdef _WIN32
        err = -1;
#else
        err = create_media_for_mpeg2t_file(psptr, name, errmsg, errlen,
                                           have_audio_driver, cc_vft);

        if (err < 0) {
            err = create_media_for_mpeg_file(psptr, name, errmsg,
                                             errlen, have_audio_driver, cc_vft);
        }
#endif
    } else {
        // raw files
        codec_data_t *cdata = NULL;
        double maxtime;
        char *desc[4];
        bool is_video = false;
        codec_plugin_t *codec;
        desc[0] = NULL;
        desc[1] = NULL;
        desc[2] = NULL;
        desc[3] = NULL;

        if (have_audio_driver) {
            cdata = audio_codec_check_for_raw_file(name,
                                                   &codec,
                                                   &maxtime,
                                                   desc,
                                                   &config);
        }
        if (cdata == NULL) {
            cdata = video_codec_check_for_raw_file(name,
                                                   &codec,
                                                   &maxtime,
                                                   desc,
                                                   &config);
            is_video = true;
        }

        if (cdata == NULL) {
            err = -1;
        } else {
            CPlayerMedia *mptr;
            /*
             * Create the player media, and the bytestream
             */
            mptr = new CPlayerMedia(psptr);

            COurInByteStreamFile *fbyte;
            fbyte = new COurInByteStreamFile(codec,
                                             cdata,
                                             maxtime);
            mptr->create(fbyte, is_video);
            mptr->set_plugin_data(codec, cdata,
                                  is_video ? get_video_vft() : NULL,
                                  is_video ? NULL : get_audio_vft());

            for (int ix = 0; ix < 4; ix++)
                if (desc[ix] != NULL)
                    psptr->set_session_desc(ix, desc[ix]);

            if (maxtime != 0.0) {
                psptr->session_set_seekable(1);
            }
            err = 0;
        }
    }

    if (err >= 0) {
        const char *temp;
        temp = psptr->get_session_desc(0);
        if (temp == NULL) {
            psptr->set_session_desc(0, name);
        }
    }
    return (err);
}