int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { if (!demuxer->seekable) { if (demuxer->file_format == DEMUXER_TYPE_AVI) mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)\n"); #ifdef CONFIG_TV else if (demuxer->file_format == DEMUXER_TYPE_TV) mp_tmsg(MSGT_SEEK, MSGL_WARN, "TV input is not seekable! (Seeking will probably be for changing channels ;)\n"); #endif else mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in this file.\n"); return 0; } // clear demux buffers: demux_flush(demuxer); demuxer->video->eof = 0; demuxer->audio->eof = 0; demuxer->sub->eof = 0; /* HACK: assume any demuxer used with these streams can cope with * the stream layer suddenly seeking to a different position under it * (nothing actually implements DEMUXER_CTRL_RESYNC now). */ struct stream *stream = demuxer->stream; if (stream->type == STREAMTYPE_DVD || stream->type == STREAMTYPE_DVDNAV) { double pts; if (flags & SEEK_ABSOLUTE) pts = 0.0f; else { if (demuxer->stream_pts == MP_NOPTS_VALUE) goto dmx_seek; pts = demuxer->stream_pts; } if (flags & SEEK_FACTOR) { double tmp = 0; if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &tmp) == STREAM_UNSUPPORTED) goto dmx_seek; pts += tmp * rel_seek_secs; } else pts += rel_seek_secs; if (stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, &pts) != STREAM_UNSUPPORTED) { demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL); return 1; } } dmx_seek: if (demuxer->desc->seek) demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags); return 1; }
static int open_f (stream_t *stream, int mode) { char *filename; mode_t m = 0; int64_t len; int fd, err; struct priv *priv = talloc_zero(stream, struct priv); stream->priv = priv; filename = stream->url; if(mode == STREAM_READ) m = O_RDONLY; else if (mode == STREAM_WRITE) //who's gonna do that ? m = O_RDWR|O_CREAT|O_TRUNC; else { mp_msg(MSGT_OPEN, MSGL_ERR, "[smb] Unknown open mode %d\n", mode); return STREAM_UNSUPPORTED; } if(!filename) { mp_msg(MSGT_OPEN,MSGL_ERR, "[smb] Bad url\n"); return STREAM_ERROR; } err = smbc_init(smb_auth_fn, 1); if (err < 0) { mp_tmsg(MSGT_OPEN,MSGL_ERR,"Cannot init the libsmbclient library: %d\n",err); return STREAM_ERROR; } fd = smbc_open(filename, m,0644); if (fd < 0) { mp_tmsg(MSGT_OPEN,MSGL_ERR,"Could not open from LAN: '%s'\n", filename); return STREAM_ERROR; } stream->flags = mode; len = 0; if(mode == STREAM_READ) { len = smbc_lseek(fd,0,SEEK_END); smbc_lseek (fd, 0, SEEK_SET); } if(len > 0 || mode == STREAM_WRITE) { stream->flags |= MP_STREAM_SEEK; stream->seek = seek; if(mode == STREAM_READ) stream->end_pos = len; } priv->fd = fd; stream->fill_buffer = fill_buffer; stream->write_buffer = write_buffer; stream->close = close_f; stream->control = control; return STREAM_OK; }
URL_t* check4proxies( const URL_t *url ) { URL_t *url_out = NULL; if( url==NULL ) return NULL; url_out = url_new( url->url ); if( !strcasecmp(url->protocol, "mp_http_proxy") ) { mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); return url_out; } // Check if the http_proxy environment variable is set. if( !strcasecmp(url->protocol, "mp_http") ) { char *proxy; proxy = getenv("http_proxy"); if( proxy!=NULL ) { // We got a proxy, build the URL to use it char *new_url; URL_t *tmp_url; URL_t *proxy_url = url_new( proxy ); if( proxy_url==NULL ) { mp_tmsg(MSGT_NETWORK,MSGL_WARN, "Invalid proxy setting... Trying without proxy.\n"); return url_out; } #ifdef HAVE_AF_INET6 if (network_ipv4_only_proxy && (gethostbyname(url->hostname)==NULL)) { mp_tmsg(MSGT_NETWORK,MSGL_WARN, "Could not resolve remote hostname for AF_INET. Trying without proxy.\n"); url_free(proxy_url); return url_out; } #endif mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n", proxy_url->url ); new_url = get_http_proxy_url(proxy_url, url->url); if( new_url==NULL ) { mp_tmsg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed.\n"); url_free(proxy_url); return url_out; } tmp_url = url_new( new_url ); if( tmp_url==NULL ) { free( new_url ); url_free( proxy_url ); return url_out; } url_free( url_out ); url_out = tmp_url; free( new_url ); url_free( proxy_url ); } } return url_out; }
static int af_open(struct af_instance* af){ af_ac3enc_t *s = af->priv; af->control=control; af->uninit=uninit; af->play=play; af->setup=s; s->lavc_acodec = avcodec_find_encoder_by_name("ac3"); if (!s->lavc_acodec) { mp_tmsg(MSGT_AFILTER, MSGL_ERR, "Audio LAVC, couldn't find encoder for codec %s.\n", "ac3"); return AF_ERROR; } s->lavc_actx = avcodec_alloc_context3(s->lavc_acodec); if (!s->lavc_actx) { mp_tmsg(MSGT_AFILTER, MSGL_ERR, "Audio LAVC, couldn't allocate context!\n"); return AF_ERROR; } const enum AVSampleFormat *fmts = s->lavc_acodec->sample_fmts; for (int i = 0; fmts[i] != AV_SAMPLE_FMT_NONE; i++) { s->in_sampleformat = af_from_avformat(fmts[i]); if (s->in_sampleformat) { s->lavc_actx->sample_fmt = fmts[i]; break; } } if (!s->in_sampleformat) { mp_msg(MSGT_AFILTER, MSGL_ERR, "Audio LAVC, encoder doesn't " "support expected sample formats!\n"); return AF_ERROR; } mp_msg(MSGT_AFILTER, MSGL_V, "[af_lavcac3enc]: in sample format: %s\n", af_fmt_to_str(s->in_sampleformat)); av_init_packet(&s->pkt); s->pending = mp_audio_buffer_create(af); if (s->cfg_bit_rate) { int i; for (i = 0; i < 19; i++) { if (ac3_bitrate_tab[i] == s->cfg_bit_rate) break; } if (i >= 19) { mp_msg(MSGT_AFILTER, MSGL_WARN, "af_lavcac3enc unable set unsupported " "bitrate %d, use default bitrate (check manpage to see " "supported bitrates).\n", s->cfg_bit_rate); s->cfg_bit_rate = 0; } } return AF_OK; }
/***************************************************************** * \brief read next part of data into buffer * \return -1 if error occured or no data available yet, otherwise - bytes read * NOTE: audio device works in non-blocking mode */ static int read_chunk(audio_in_t *ai, unsigned char *buffer) { int ret; switch (ai->type) { #ifdef CONFIG_ALSA case AUDIO_IN_ALSA: //device opened in non-blocking mode ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { if (ret < 0) { if (ret==-EAGAIN) return -1; mp_tmsg(MSGT_RADIO, MSGL_ERR, "\nError reading audio: %s\n", snd_strerror(ret)); if (ret == -EPIPE) { if (ai_alsa_xrun(ai) == 0) { mp_tmsg(MSGT_RADIO, MSGL_ERR, "Recovered from cross-run, some frames may be left out!\n"); } else { mp_tmsg(MSGT_RADIO, MSGL_ERR, "Fatal error, cannot recover!\n"); } } } else { mp_tmsg(MSGT_RADIO, MSGL_ERR, "\nNot enough audio samples!\n"); } return -1; } return ret; #endif #ifdef CONFIG_OSS_AUDIO case AUDIO_IN_OSS: { int bt=0; /* we must return exactly blocksize bytes, so if we have got any bytes at first call to read, we will loop untils get all blocksize bytes otherwise we will return -1 */ while(bt<ai->blocksize){ //device opened in non-blocking mode ret = read(ai->oss.audio_fd, buffer+bt, ai->blocksize-bt); if (ret==ai->blocksize) return ret; if (ret<0){ if (errno==EAGAIN && bt==0) return -1; //no data avail yet if (errno==EAGAIN) { usleep(1000); continue;} //nilling buffer to blocksize size mp_tmsg(MSGT_RADIO, MSGL_ERR, "\nError reading audio: %s\n", strerror(errno)); return -1; } bt+=ret; } return bt; } #endif default: return -1; } }
static int cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*, cddb_data_t*), cddb_data_t *cddb_data) { char request[4096]; int fd, ret = 0; URL_t *url; HTTP_header_t *http_hdr; if (reply_parser == NULL || command == NULL || cddb_data == NULL) return -1; sprintf(request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello, cddb_data->freedb_proto_level); mp_msg(MSGT_OPEN, MSGL_INFO,"Request[%s]\n", request); url = url_new(request); if (url == NULL) { mp_tmsg(MSGT_DEMUX, MSGL_ERR, "not a valid URL\n"); return -1; } fd = http_send_request(url,0); if (fd < 0) { mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Failed to send the HTTP request.\n"); return -1; } http_hdr = http_read_response(fd); if (http_hdr == NULL) { mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Failed to read the HTTP response.\n"); return -1; } http_debug_hdr(http_hdr); mp_msg(MSGT_OPEN, MSGL_INFO,"body=[%s]\n", http_hdr->body); switch (http_hdr->status_code) { case 200: ret = reply_parser(http_hdr, cddb_data); break; case 400: mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Not Found.\n"); break; default: mp_tmsg(MSGT_DEMUX, MSGL_ERR, "unknown error code\n"); } http_free(http_hdr); url_free(url); return ret; }
int tv_set_norm(tvi_handle_t *tvh, char* norm) { tvh->norm = norm_from_string(tvh, norm); mp_tmsg(MSGT_TV, MSGL_V, "Selected norm : %s\n", norm); if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) { mp_tmsg(MSGT_TV, MSGL_ERR, "Error: Cannot set norm!\n"); return 0; } return 1; }
static int tv_set_norm_i(tvi_handle_t *tvh, int norm) { tvh->norm = norm; mp_tmsg(MSGT_TV, MSGL_V, "Selected norm id: %d\n", norm); if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) { mp_tmsg(MSGT_TV, MSGL_ERR, "Error: Cannot set norm!\n"); return 0; } return 1; }
static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { if(z_compression == 0) { mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Warning: compression level set to 0, compression disabled!\n"); mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Info: Use -vo png:z=<n> to set compression level from 0 to 9.\n"); mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); } mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression); return 0; }
const ao_functions_t* init_best_audio_out(char** ao_list,int use_plugin,int rate,int channels,int format,int flags){ int i; // first try the preferred drivers, with their optional subdevice param: if(ao_list && ao_list[0]) while(ao_list[0][0]){ char* ao=ao_list[0]; int ao_len; free(ao_subdevice); ao_subdevice = NULL; ao_subdevice=strchr(ao,':'); if(ao_subdevice){ ao_len = ao_subdevice - ao; ao_subdevice = strdup(&ao[ao_len + 1]); } else ao_len = strlen(ao); mp_tmsg(MSGT_AO, MSGL_V, "Trying preferred audio driver '%.*s', options '%s'\n", ao_len, ao, ao_subdevice ? ao_subdevice : "[none]"); for(i=0;audio_out_drivers[i];i++){ const ao_functions_t* audio_out=audio_out_drivers[i]; if(!strncmp(audio_out->info->short_name,ao,ao_len)){ // name matches, try it if(audio_out->init(rate,channels,format,flags)) return audio_out; // success! else mp_tmsg(MSGT_AO, MSGL_WARN, "Failed to initialize audio driver '%s'\n", ao); break; } } if (!audio_out_drivers[i]) // we searched through the entire list mp_tmsg(MSGT_AO, MSGL_WARN, "No such audio driver '%.*s'\n", ao_len, ao); // continue... ++ao_list; if(!(ao_list[0])) return NULL; // do NOT fallback to others } free(ao_subdevice); ao_subdevice = NULL; mp_tmsg(MSGT_AO, MSGL_V, "Trying every known audio driver...\n"); // now try the rest... for(i=0;audio_out_drivers[i];i++){ const ao_functions_t* audio_out=audio_out_drivers[i]; // if(audio_out->control(AOCONTROL_QUERY_FORMAT, (int)format) == CONTROL_TRUE) if(audio_out->init(rate,channels,format,flags)) return audio_out; // success! } return NULL; }
int audio_init_best_codec(struct dec_audio *d_audio, char *audio_decoders) { assert(!d_audio->ad_driver); audio_reset_decoding(d_audio); struct mp_decoder_entry *decoder = NULL; struct mp_decoder_list *list = audio_select_decoders(d_audio->header->codec, audio_decoders); mp_print_decoders(MSGT_DECAUDIO, MSGL_V, "Codec list:", list); for (int n = 0; n < list->num_entries; n++) { struct mp_decoder_entry *sel = &list->entries[n]; const struct ad_functions *driver = find_driver(sel->family); if (!driver) continue; mp_tmsg(MSGT_DECAUDIO, MSGL_V, "Opening audio decoder %s:%s\n", sel->family, sel->decoder); d_audio->ad_driver = driver; if (init_audio_codec(d_audio, sel->decoder)) { decoder = sel; break; } mp_tmsg(MSGT_DECAUDIO, MSGL_WARN, "Audio decoder init failed for " "%s:%s\n", sel->family, sel->decoder); } if (d_audio->ad_driver) { d_audio->decoder_desc = talloc_asprintf(d_audio, "%s [%s:%s]", decoder->desc, decoder->family, decoder->decoder); mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Selected audio codec: %s\n", d_audio->decoder_desc); mp_msg(MSGT_DECAUDIO, MSGL_V, "AUDIO: %d Hz, %d ch, %s\n", d_audio->decoded.rate, d_audio->decoded.channels.num, af_fmt_to_str(d_audio->decoded.format)); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_BITRATE=%d\nID_AUDIO_RATE=%d\n" "ID_AUDIO_NCH=%d\n", d_audio->i_bps * 8, d_audio->decoded.rate, d_audio->decoded.channels.num); } else { mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Failed to initialize an audio decoder for codec '%s'.\n", d_audio->header->codec ? d_audio->header->codec : "<unknown>"); } talloc_free(list); return !!d_audio->ad_driver; }
static void read_cmd(menu_t* menu,int cmd) { switch(cmd) { case MENU_CMD_RIGHT: case MENU_CMD_OK: { int d = 1; char str[15]; play_tree_t* i; mp_cmd_t* c; play_tree_iter_t* playtree_iter = mpctx_get_playtree_iter(menu->ctx); if(playtree_iter->tree == mpriv->p.current->pt) break; if(playtree_iter->tree->parent && mpriv->p.current->pt == playtree_iter->tree->parent) snprintf(str,15,"pt_up_step 1"); else { for(i = playtree_iter->tree->next; i != NULL ; i = i->next) { if(i == mpriv->p.current->pt) break; d++; } if(i == NULL) { d = -1; for(i = playtree_iter->tree->prev; i != NULL ; i = i->prev) { if(i == mpriv->p.current->pt) break; d--; } if(i == NULL) { mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Can't find the target item ????\n"); break; } } snprintf(str,15,"pt_step %d",d); } c = mp_input_parse_cmd(str); if(c) { if(mpriv->auto_close) mp_input_queue_cmd(menu->input_ctx, mp_input_parse_cmd("menu hide")); mp_input_queue_cmd(menu->input_ctx, c); } else mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Failed to build command: %s.\n",str); } break; default: menu_list_read_cmd(menu,cmd); } }
int init_best_audio_codec(sh_audio_t *sh_audio, char *audio_decoders) { assert(!sh_audio->initialized); struct mp_decoder_entry *decoder = NULL; struct mp_decoder_list *list = mp_select_audio_decoders(sh_audio->gsh->codec, audio_decoders); mp_print_decoders(MSGT_DECAUDIO, MSGL_V, "Codec list:", list); for (int n = 0; n < list->num_entries; n++) { struct mp_decoder_entry *sel = &list->entries[n]; const struct ad_functions *driver = find_driver(sel->family); if (!driver) continue; mp_tmsg(MSGT_DECAUDIO, MSGL_V, "Opening audio decoder %s:%s\n", sel->family, sel->decoder); sh_audio->ad_driver = driver; if (init_audio_codec(sh_audio, sel->decoder)) { decoder = sel; break; } sh_audio->ad_driver = NULL; mp_tmsg(MSGT_DECAUDIO, MSGL_WARN, "Audio decoder init failed for " "%s:%s\n", sel->family, sel->decoder); } if (sh_audio->initialized) { sh_audio->gsh->decoder_desc = talloc_asprintf(NULL, "%s [%s:%s]", decoder->desc, decoder->family, decoder->decoder); mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Selected audio codec: %s\n", sh_audio->gsh->decoder_desc); mp_msg(MSGT_DECAUDIO, MSGL_V, "AUDIO: %d Hz, %d ch, %s\n", sh_audio->samplerate, sh_audio->channels.num, af_fmt2str_short(sh_audio->sample_format)); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_BITRATE=%d\nID_AUDIO_RATE=%d\n" "ID_AUDIO_NCH=%d\n", sh_audio->i_bps * 8, sh_audio->samplerate, sh_audio->channels.num); } else { mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Failed to initialize an audio decoder for codec '%s'.\n", sh_audio->gsh->codec ? sh_audio->gsh->codec : "<unknown>"); } talloc_free(list); return sh_audio->initialized; }
int dvd_sid_from_lang(stream_t *stream, char **lang) { dvd_priv_t *d=stream->priv; int code,i; for (int n = 0; lang[n]; n++) { code = lang[n][1] | (lang[n][0] << 8); for(i=0;i<d->nr_of_subtitles;i++) { if(d->subtitles[i].language==code) { mp_tmsg(MSGT_OPEN,MSGL_INFO,"Selected DVD subtitle channel: %d language: %c%c\n", i, lang[n][0], lang[n][1]); return d->subtitles[i].id; } } } mp_tmsg(MSGT_OPEN,MSGL_WARN,"No matching DVD subtitle language found!\n"); return -1; }
int stream_seek_internal(stream_t *s, off_t newpos) { if(newpos==0 || newpos!=s->pos){ switch(s->type){ case STREAMTYPE_STREAM: //s->pos=newpos; // real seek // Some streaming protocol allow to seek backward and forward // A function call that return -1 can tell that the protocol // doesn't support seeking. #ifdef CONFIG_NETWORKING if(s->seek) { // new stream seek is much cleaner than streaming_ctrl one if(!s->seek(s,newpos)) { mp_tmsg(MSGT_STREAM,MSGL_ERR, "Seek failed\n"); return 0; } break; } if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_seek ) { if( s->streaming_ctrl->streaming_seek( s->fd, newpos, s->streaming_ctrl )<0 ) { mp_tmsg(MSGT_STREAM,MSGL_INFO,"Stream not seekable!\n"); return 1; } break; } #endif if(newpos<s->pos){ mp_tmsg(MSGT_STREAM, MSGL_INFO, "Cannot seek backward in linear streams!\n"); return 1; } break; default: // This should at the beginning as soon as all streams are converted if(!s->seek) return 0; // Now seek if(!s->seek(s,newpos)) { mp_tmsg(MSGT_STREAM,MSGL_ERR, "Seek failed\n"); return 0; } } // putchar('.');fflush(stdout); //} else { // putchar('%');fflush(stdout); } return -1; }
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param) { char **info = demuxer->info; int n = 0; for (n = 0; info && info[2 * n] != NULL; n++) { if (!bstrcasecmp(opt, bstr(info[2*n]))) { if (!bstrcmp(param, bstr(info[2*n + 1]))) { mp_msg(MSGT_DEMUX, MSGL_V, "Demuxer info %.*s set to unchanged value %.*s\n", BSTR_P(opt), BSTR_P(param)); return 0; } mp_tmsg(MSGT_DEMUX, MSGL_INFO, "Demuxer info %.*s changed to %.*s\n", BSTR_P(opt), BSTR_P(param)); talloc_free(info[2*n + 1]); info[2*n + 1] = talloc_strndup(demuxer->info, param.start, param.len); return 0; } } info = demuxer->info = talloc_realloc(demuxer, info, char *, 2 * (n + 2)); info[2*n] = talloc_strndup(demuxer->info, opt.start, opt.len); info[2*n + 1] = talloc_strndup(demuxer->info, param.start, param.len); memset(&info[2 * (n + 1)], 0, 2 * sizeof(char *)); return 1; }
static void init_plugins_from_dir(const char *plugin_dir){ DIR *dir; struct dirent *ent; dir = opendir(plugin_dir); if (!dir) return; while ((ent = readdir(dir)) != NULL){ char filename[strlen(plugin_dir)+strlen(ent->d_name)+4]; void* handle; sprintf(filename, "%s/%s", plugin_dir, ent->d_name); handle=dlopen(filename, RTLD_NOW); if(handle){ void *(*gpi) (void); gpi=dlsym(handle, "get_iplugin_info"); if(gpi){ InputPlugin *p=gpi(); mp_tmsg(MSGT_DEMUX, MSGL_INFO, "Found plugin: %s (%s).\n", ent->d_name,p->description); p->handle = handle; p->filename = strdup(filename); p->get_vis_type = input_get_vis_type; p->add_vis_pcm = input_add_vis_pcm; p->set_info = input_set_info; p->set_info_text = input_set_info_text; if(p->init) p->init(); input_plugins[no_plugins++]=p; } else dlclose(handle); } } closedir(dir); }
static int decode_audio(sh_audio_t *audio, unsigned char *buf, int minlen, int maxlen) { int len=0; dv_decoder_t* decoder=audio->context; //global_rawdv_decoder; unsigned char* dv_audio_frame=NULL; int xx=ds_get_packet(audio->ds,&dv_audio_frame); if(xx<=0 || !dv_audio_frame) return 0; // EOF? dv_parse_header(decoder, dv_audio_frame); if(xx!=decoder->frame_size) mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[AD_LIBDV] Warning! Audio framesize differs! read=%d hdr=%d.\n", xx, decoder->frame_size); if (dv_decode_full_audio(decoder, dv_audio_frame,(int16_t**) audioBuffers)) { /* Interleave the audio into a single buffer */ int i=0; int16_t *bufP=(int16_t*)buf; // printf("samples=%d/%d chans=%d mem=%d \n",decoder->audio->samples_this_frame,DV_AUDIO_MAX_SAMPLES, // decoder->audio->num_channels, decoder->audio->samples_this_frame*decoder->audio->num_channels*2); // return (44100/30)*4; for (i=0; i < decoder->audio->samples_this_frame; i++) { int ch; for (ch=0; ch < decoder->audio->num_channels; ch++) bufP[len++] = audioBuffers[ch][i]; } } return len*2; }
static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) { // calculate the missing parameters: if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width; if(vf->priv->crop_h<=0 || vf->priv->crop_h>height) vf->priv->crop_h=height; if(vf->priv->crop_x<0) vf->priv->crop_x=(width-vf->priv->crop_w)/2; if(vf->priv->crop_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2; // rounding: struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(outfmt); vf->priv->crop_x = MP_ALIGN_DOWN(vf->priv->crop_x, fmt.align_x); vf->priv->crop_y = MP_ALIGN_DOWN(vf->priv->crop_y, fmt.align_y); // check: if(vf->priv->crop_w+vf->priv->crop_x>width || vf->priv->crop_h+vf->priv->crop_y>height){ mp_tmsg(MSGT_VFILTER, MSGL_WARN, "[CROP] Bad position/width/height - cropped area outside of the original!\n"); return 0; } vf_rescale_dsize(&d_width, &d_height, width, height, vf->priv->crop_w, vf->priv->crop_h); return vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt); }
static void update_audio_block_size(demuxer_t *demux) { avi_priv_t *priv = demux->priv; sh_audio_t *sh = demux->audio->sh; if (!sh) return; priv->audio_block_size = sh->audio.dwSampleSize; if (sh->wf) { priv->audio_block_size = sh->wf->nBlockAlign; if (!priv->audio_block_size) { // for PCM audio we can calculate the blocksize: if (sh->format == 1) priv->audio_block_size = sh->wf->nChannels*(sh->wf->wBitsPerSample/8); else priv->audio_block_size = 1; // hope the best... } else { // workaround old mencoder bug: if (sh->audio.dwSampleSize == 1 && sh->audio.dwScale == 1 && (sh->wf->nBlockAlign == 1152 || sh->wf->nBlockAlign == 576)) { mp_tmsg(MSGT_DEMUX,MSGL_WARN,"AVI: Working around CBR-MP3 nBlockAlign header bug!\n"); priv->audio_block_size = 1; } } } }
static inline int set_frequency(radio_priv_t* priv,float frequency) { if ((frequency<priv->rangelow)||(frequency>priv->rangehigh)) { mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] Wrong frequency: %.2f\n",frequency); return STREAM_ERROR; } if(priv->driver->set_frequency(priv,frequency)!=STREAM_OK) return STREAM_ERROR; #ifdef CONFIG_RADIO_CAPTURE if(clear_buffer(priv)!=STREAM_OK) { mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] Clearing buffer failed: %s\n",strerror(errno)); return STREAM_ERROR; } #endif return STREAM_OK; }
/* open & setup audio device */ static int init (int rate, int channels, int format, int flags) { if (ivtv_fd < 0) return 0; if (format != AF_FORMAT_MPEG2) { mp_msg (MSGT_AO, MSGL_FATAL, "AO: [ivtv] can only handle MPEG audio streams.\n"); return 0; } ao_data.outburst = 2048; ao_data.samplerate = rate; ao_data.channels = channels; ao_data.format = AF_FORMAT_MPEG2; ao_data.buffersize = 2048; ao_data.bps = rate * 2 * 2; ao_data.brokenpts = 0; freq = rate; /* check for supported audio rate */ if (rate != 32000 || rate != 41000 || rate != 48000) { mp_tmsg (MSGT_AO, MSGL_ERR, "[AO MPEGPES] %d Hz not supported, try to resample.\n", rate); rate = 48000; } return 1; }
static int asf_mmst_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { int len; while( stream_ctrl->buffer_size==0 ) { // buffer is empty - fill it! int ret = get_media_packet( fd, packet_length1, stream_ctrl); if( ret<0 ) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"get_media_packet error : %s\n",strerror(errno)); return -1; } else if (ret==0) //EOF? return ret; } len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; if(len>size) len=size; memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); stream_ctrl->buffer_pos += len; if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { free( stream_ctrl->buffer ); stream_ctrl->buffer = NULL; stream_ctrl->buffer_size = 0; stream_ctrl->buffer_pos = 0; } return len; }
static void send_command (int s, int command, uint32_t switches, uint32_t extra, int length, char *data) { command_t cmd; int len8; len8 = (length + 7) / 8; cmd.num_bytes = 0; put_32 (&cmd, 0x00000001); /* start sequence */ put_32 (&cmd, 0xB00BFACE); /* #-)) */ put_32 (&cmd, len8*8 + 32); put_32 (&cmd, 0x20534d4d); /* protocol type "MMS " */ put_32 (&cmd, len8 + 4); put_32 (&cmd, seq_num); seq_num++; put_32 (&cmd, 0x0); /* unknown */ put_32 (&cmd, 0x0); put_32 (&cmd, len8+2); put_32 (&cmd, 0x00030000 | command); /* dir | command */ put_32 (&cmd, switches); put_32 (&cmd, extra); memcpy (&cmd.buf[48], data, length); if (length & 7) memset(&cmd.buf[48 + length], 0, 8 - (length & 7)); if (send (s, cmd.buf, len8*8+48, 0) != (len8*8+48)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"write error\n"); } }
static void get_image(struct vf_instance* vf, mp_image_t *mpi){ // if(mpi->type==MP_IMGTYPE_IPB) return; // not yet working #ifdef OSD_SUPPORT if(vf->priv->osd_enabled && (mpi->flags&MP_IMGFLAG_PRESERVE)){ // check if we have to render osd! osd_update(vf->priv->osd, vf->priv->exp_w, vf->priv->exp_h); if(vo_osd_check_range_update(vf->priv->exp_x,vf->priv->exp_y, vf->priv->exp_x+mpi->w,vf->priv->exp_y+mpi->h)) return; } #endif if(vf->priv->exp_w==mpi->width || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)) ){ // try full DR ! mpi->priv=vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, mpi->type, mpi->flags, FFMAX(vf->priv->exp_w, mpi->width +vf->priv->exp_x), FFMAX(vf->priv->exp_h, mpi->height+vf->priv->exp_y)); if((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) && !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)){ mp_tmsg(MSGT_VFILTER, MSGL_INFO, "Full DR not possible, trying SLICES instead!\n"); return; } // set up mpi as a cropped-down image of dmpi: if(mpi->flags&MP_IMGFLAG_PLANAR){ mpi->planes[0]=vf->dmpi->planes[0]+ vf->priv->exp_y*vf->dmpi->stride[0]+vf->priv->exp_x; mpi->planes[1]=vf->dmpi->planes[1]+ (vf->priv->exp_y>>mpi->chroma_y_shift)*vf->dmpi->stride[1]+(vf->priv->exp_x>>mpi->chroma_x_shift); mpi->planes[2]=vf->dmpi->planes[2]+ (vf->priv->exp_y>>mpi->chroma_y_shift)*vf->dmpi->stride[2]+(vf->priv->exp_x>>mpi->chroma_x_shift); mpi->stride[1]=vf->dmpi->stride[1]; mpi->stride[2]=vf->dmpi->stride[2]; } else {
ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, char *charset) { ASS_Track *track; struct stream *s = open_stream(fname, NULL, NULL); if (!s) // Stream code should have printed an error already return NULL; struct bstr content = stream_read_complete(s, NULL, 100000000, 1); if (content.start == NULL) mp_tmsg(MSGT_ASS, MSGL_ERR, "Refusing to load subtitle file " "larger than 100 MB: %s\n", fname); free_stream(s); if (content.len == 0) { talloc_free(content.start); return NULL; } content.start[content.len] = 0; track = ass_read_memory(library, content.start, content.len, charset); if (track) { free(track->name); track->name = strdup(fname); } talloc_free(content.start); return track; }
static void dvdpcm_header(sh_audio_t *sh) { if (sh->format != 0x10001) return; WAVEFORMATEX *wf = calloc(sizeof(*wf), 1); if(sh->codecdata_len==3){ // we have LPCM header: unsigned char h=sh->codecdata[1]; wf->nChannels=1+(h&7); switch((h>>4)&3){ case 0: wf->nSamplesPerSec=48000;break; case 1: wf->nSamplesPerSec=96000;break; case 2: wf->nSamplesPerSec=44100;break; case 3: wf->nSamplesPerSec=32000;break; } switch ((h >> 6) & 3) { case 0: wf->wBitsPerSample = 2 * 8; break; case 1: mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "Samples of this format are needed to improve support. Please contact the developers.\n"); wf->nAvgBytesPerSec = wf->nChannels * wf->nSamplesPerSec * 5 / 2; case 2: wf->wBitsPerSample = 3 * 8; break; default: wf->wBitsPerSample = 2 * 8; } } else {
/***************************************************************** * \brief grab next frame from audio device * \parameter buffer - store buffer * \parameter len - store buffer size in bytes * \return number of bytes written into buffer * * grabs len (or less) bytes from ringbuffer into buffer * if ringbuffer is empty waits until len bytes of data will be available * * priv->audio_cnt - size (in bytes) of ringbuffer's filled part * priv->audio_drop - size (in bytes) of dropped data (if no space in ringbuffer) * priv->audio_head - index of first byte in filled part * priv->audio_tail - index of last byte in filled part * * NOTE: audio_tail always aligned by priv->audio_in.blocksize * audio_head may NOT. */ static int grab_audio_frame(radio_priv_t *priv, char *buffer, int len) { int i; mp_tmsg(MSGT_RADIO, MSGL_DBG3, "[radio] %s: in buffer=%d dropped=%d\n","grab_audio_frame",priv->audio_cnt,priv->audio_drop); /* Cache buffer must be filled by some audio packets when playing starts. Otherwise MPlayer will quit with EOF error. Probably, there is need more carefull checking rather than simple 'for' loop (something like timer or similar). 1000ms delay will happen only at first buffer filling. At next call function just fills buffer until either buffer full or no data from driver available. */ for (i=0; i<1000 && !priv->audio_cnt; i++) { //read_chunk fills exact priv->blocksize bytes if(read_chunk(&priv->audio_in, priv->audio_ringbuffer+priv->audio_tail) < 0) { //sleppeing only when waiting first block to fill empty buffer if (!priv->audio_cnt) { usleep(1000); continue; } else break; } priv->audio_cnt+=priv->audio_in.blocksize; priv->audio_tail = (priv->audio_tail+priv->audio_in.blocksize) % priv->audio_buffer_size; } if(priv->audio_cnt<len) len=priv->audio_cnt; memcpy(buffer, priv->audio_ringbuffer+priv->audio_head,len); priv->audio_head = (priv->audio_head+len) % priv->audio_buffer_size; priv->audio_cnt-=len; return len; }
static demuxer_t* demux_open_hack_avi(demuxer_t *demuxer) { struct MPOpts *opts = demuxer->opts; sh_audio_t* sh_a; demuxer = demux_open_avi(demuxer); if(!demuxer) return NULL; // failed to open sh_a = demuxer->audio->sh; if(demuxer->audio->id != -2 && sh_a) { #ifdef CONFIG_OGGVORBIS // support for Ogg-in-AVI: if(sh_a->format == 0xFFFE) demuxer = init_avi_with_ogg(demuxer); else if(sh_a->format == 0x674F) { stream_t* s; demuxer_t *od; s = new_ds_stream(demuxer->audio); od = new_demuxer(opts, s,DEMUXER_TYPE_OGG,-1,-2,-2,NULL); if(!demux_ogg_open(od)) { mp_tmsg( MSGT_DEMUXER,MSGL_ERR,"Unable to open the Ogg demuxer.\n"); free_stream(s); demuxer->audio->id = -2; } else demuxer = new_demuxers_demuxer(demuxer,od,demuxer); } #endif } return demuxer; }
static int cddb_retrieve(cddb_data_t *cddb_data) { char offsets[1024], command[1024]; char *ptr; unsigned int i, time_len; int ret; ptr = offsets; for (i = 0; i < cddb_data->tracks ; i++) { unsigned space = sizeof(offsets) - (ptr - offsets); if (space < 40) break; ptr += snprintf(ptr, space, "%d+", cdtoc[i].frame); } ptr[0] = 0; time_len = (cdtoc[cddb_data->tracks].frame)/75; cddb_data->freedb_server = DEFAULT_FREEDB_SERVER; cddb_data->freedb_proto_level = 1; cddb_data->xmcd_file = NULL; cddb_create_hello(cddb_data); if (cddb_get_proto_level(cddb_data) < 0) { mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Failed to get the protocol level.\n"); return -1; } snprintf(command, sizeof(command), "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id, cddb_data->tracks, offsets, time_len); ret = cddb_http_request(command, cddb_query_parse, cddb_data); if (ret < 0) return -1; free(cddb_data->cache_dir); return 0; }