• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/minidlna/ffmpeg-0.5.1/

Lines Matching refs:is

5  * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
12 * FFmpeg is distributed in the hope that it will be useful,
56 /* no AV sync correction is done if below the AV sync threshold */
58 /* no AV correction is done if too big error */
178 static int audio_write_get_buf_size(VideoState *is);
652 static void video_image_display(VideoState *is)
662 vp = &is->pictq[is->pictq_rindex];
665 if (is->video_st->sample_aspect_ratio.num)
666 aspect_ratio = av_q2d(is->video_st->sample_aspect_ratio);
667 else if (is->video_st->codec->sample_aspect_ratio.num)
668 aspect_ratio = av_q2d(is->video_st->codec->sample_aspect_ratio);
673 aspect_ratio *= (float)is->video_st->codec->width / is->video_st->codec->height;
674 /* if an active format is indicated, then it overrides the
677 if (is->video_st->codec->dtg_active_format != is->dtg_active_format) {
678 is->dtg_active_format = is->video_st->codec->dtg_active_format;
679 printf("dtg_active_format=%d\n", is->dtg_active_format);
683 switch(is->video_st->codec->dtg_active_format) {
709 if (is->subtitle_st)
711 if (is->subpq_size > 0)
713 sp = &is->subpq[is->subpq_rindex];
738 height = is->height;
740 if (width > is->width) {
741 width = is->width;
744 x = (is->width - width) / 2;
745 y = (is->height - height) / 2;
746 if (!is->no_background) {
748 // fill_border(is, x, y, width, height, QERGB(0x00, 0x00, 0x00));
750 is->no_background = 0;
752 rect.x = is->xleft + x;
753 rect.y = is->ytop + y;
760 is->xleft, is->ytop, is->width, is->height,
863 static int video_open(VideoState *is){
876 }else if (is->video_st && is->video_st->codec->width){
877 w = is->video_st->codec->width;
878 h = is->video_st->codec->height;
895 is->width = screen->w;
896 is->height = screen->h;
902 static void video_display(VideoState *is)
906 if (is->audio_st && is->show_audio)
907 video_audio_display(is);
908 else if (is->video_st)
909 video_image_display(is);
922 static void schedule_refresh(VideoState *is, int delay)
924 if(!delay) delay=1; //SDL seems to be buggy when the delay is 0
925 SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
929 static double get_audio_clock(VideoState *is)
933 pts = is->audio_clock;
934 hw_buf_size = audio_write_get_buf_size(is);
936 if (is->audio_st) {
937 bytes_per_sec = is->audio_st->codec->sample_rate *
938 2 * is->audio_st->codec->channels;
946 static double get_video_clock(VideoState *is)
949 if (is->paused) {
952 delta = (av_gettime() - is->video_current_pts_time) / 1000000.0;
954 return is->video_current_pts + delta;
958 static double get_external_clock(VideoState *is)
962 return is->external_clock + ((ti - is->external_clock_time) * 1e-6);
966 static double get_master_clock(VideoState *is)
970 if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) {
971 if (is->video_st)
972 val = get_video_clock(is);
974 val = get_audio_clock(is);
975 } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) {
976 if (is->audio_st)
977 val = get_audio_clock(is);
979 val = get_video_clock(is);
981 val = get_external_clock(is);
987 static void stream_seek(VideoState *is, int64_t pos, int rel)
989 if (!is->seek_req) {
990 is->seek_pos = pos;
991 is->seek_flags = rel < 0 ? AVSEEK_FLAG_BACKWARD : 0;
993 is->seek_flags |= AVSEEK_FLAG_BYTE;
994 is->seek_req = 1;
999 static void stream_pause(VideoState *is)
1001 is->paused = !is->paused;
1002 if (!is->paused) {
1003 is->video_current_pts = get_video_clock(is);
1004 is->frame_timer += (av_gettime() - is->video_current_pts_time) / 1000000.0;
1008 static double compute_frame_delay(double frame_current_pts, VideoState *is)
1013 delay = frame_current_pts - is->frame_last_pts;
1016 delay = is->frame_last_delay;
1018 is->frame_last_delay = delay;
1020 is->frame_last_pts = frame_current_pts;
1023 if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) ||
1024 is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) {
1025 /* if video is slave, we try to correct big delays by
1027 ref_clock = get_master_clock(is);
1032 if it is the best guess */
1042 is->frame_timer += delay;
1045 actual_delay = is->frame_timer - (av_gettime() / 1000000.0);
1062 VideoState *is = opaque;
1067 if (is->video_st) {
1068 if (is->pictq_size == 0) {
1070 schedule_refresh(is, 1);
1073 vp = &is->pictq[is->pictq_rindex];
1076 is->video_current_pts = vp->pts;
1077 is->video_current_pts_time = av_gettime();
1080 schedule_refresh(is, (int)(compute_frame_delay(vp->pts, is) * 1000 + 0.5));
1082 if(is->subtitle_st) {
1083 if (is->subtitle_stream_changed) {
1084 SDL_LockMutex(is->subpq_mutex);
1086 while (is->subpq_size) {
1087 free_subpicture(&is->subpq[is->subpq_rindex]);
1090 if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE)
1091 is->subpq_rindex = 0;
1093 is->subpq_size--;
1095 is->subtitle_stream_changed = 0;
1097 SDL_CondSignal(is->subpq_cond);
1098 SDL_UnlockMutex(is->subpq_mutex);
1100 if (is->subpq_size > 0) {
1101 sp = &is->subpq[is->subpq_rindex];
1103 if (is->subpq_size > 1)
1104 sp2 = &is->subpq[(is->subpq_rindex + 1) % SUBPICTURE_QUEUE_SIZE];
1108 if ((is->video_current_pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
1109 || (sp2 && is->video_current_pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000))))
1114 if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE)
1115 is->subpq_rindex = 0;
1117 SDL_LockMutex(is->subpq_mutex);
1118 is->subpq_size--;
1119 SDL_CondSignal(is->subpq_cond);
1120 SDL_UnlockMutex(is->subpq_mutex);
1127 video_display(is);
1130 if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
1131 is->pictq_rindex = 0;
1133 SDL_LockMutex(is->pictq_mutex);
1134 is->pictq_size--;
1135 SDL_CondSignal(is->pictq_cond);
1136 SDL_UnlockMutex(is->pictq_mutex);
1138 } else if (is->audio_st) {
1141 schedule_refresh(is, 40);
1147 video_display(is);
1149 schedule_refresh(is, 100);
1162 if (is->audio_st)
1163 aqsize = is->audioq.size;
1164 if (is->video_st)
1165 vqsize = is->videoq.size;
1166 if (is->subtitle_st)
1167 sqsize = is->subtitleq.size;
1169 if (is->audio_st && is->video_st)
1170 av_diff = get_audio_clock(is) - get_video_clock(is);
1172 get_master_clock(is), av_diff, aqsize / 1024, vqsize / 1024, sqsize);
1183 VideoState *is = opaque;
1186 vp = &is->pictq[is->pictq_windex];
1194 switch(is->video_st->codec->pix_fmt) {
1208 vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec->width,
1209 is->video_st->codec->height,
1212 vp->width = is->video_st->codec->width;
1213 vp->height = is->video_st->codec->height;
1215 SDL_LockMutex(is->pictq_mutex);
1217 SDL_CondSignal(is->pictq_cond);
1218 SDL_UnlockMutex(is->pictq_mutex);
1225 static int queue_picture(VideoState *is, AVFrame *src_frame, double pts)
1233 SDL_LockMutex(is->pictq_mutex);
1234 while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE &&
1235 !is->videoq.abort_request) {
1236 SDL_CondWait(is->pictq_cond, is->pictq_mutex);
1238 SDL_UnlockMutex(is->pictq_mutex);
1240 if (is->videoq.abort_request)
1243 vp = &is->pictq[is->pictq_windex];
1247 vp->width != is->video_st->codec->width ||
1248 vp->height != is->video_st->codec->height) {
1256 event.user.data1 = is;
1259 /* wait until the picture is allocated */
1260 SDL_LockMutex(is->pictq_mutex);
1261 while (!vp->allocated && !is->videoq.abort_request) {
1262 SDL_CondWait(is->pictq_cond, is->pictq_mutex);
1264 SDL_UnlockMutex(is->pictq_mutex);
1266 if (is->videoq.abort_request)
1270 /* if the frame is not skipped, then display it */
1285 is->video_st->codec->width, is->video_st->codec->height,
1286 is->video_st->codec->pix_fmt,
1287 is->video_st->codec->width, is->video_st->codec->height,
1294 0, is->video_st->codec->height, pict.data, pict.linesize);
1301 if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE)
1302 is->pictq_windex = 0;
1303 SDL_LockMutex(is->pictq_mutex);
1304 is->pictq_size++;
1305 SDL_UnlockMutex(is->pictq_mutex);
1311 * compute the exact PTS for the picture if it is omitted in the stream
1314 static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1)
1322 is->video_clock = pts;
1324 pts = is->video_clock;
1327 frame_delay = av_q2d(is->video_st->codec->time_base);
1331 is->video_clock += frame_delay;
1346 return queue_picture(is, src_frame, pts);
1351 VideoState *is = arg;
1358 while (is->paused && !is->videoq.abort_request) {
1361 if (packet_queue_get(&is->videoq, pkt, 1) < 0)
1365 avcodec_flush_buffers(is->video_st->codec);
1369 /* NOTE: ipts is the PTS of the _first_ picture beginning in
1371 is->video_st->codec->reordered_opaque= pkt->pts;
1372 len1 = avcodec_decode_video(is->video_st->codec,
1383 pts *= av_q2d(is->video_st->time_base);
1388 if (output_picture2(is, frame, pts) < 0)
1403 VideoState *is = arg;
1412 while (is->paused && !is->subtitleq.abort_request) {
1415 if (packet_queue_get(&is->subtitleq, pkt, 1) < 0)
1419 avcodec_flush_buffers(is->subtitle_st->codec);
1422 SDL_LockMutex(is->subpq_mutex);
1423 while (is->subpq_size >= SUBPICTURE_QUEUE_SIZE &&
1424 !is->subtitleq.abort_request) {
1425 SDL_CondWait(is->subpq_cond, is->subpq_mutex);
1427 SDL_UnlockMutex(is->subpq_mutex);
1429 if (is->subtitleq.abort_request)
1432 sp = &is->subpq[is->subpq_windex];
1434 /* NOTE: ipts is the PTS of the _first_ picture beginning in
1438 pts = av_q2d(is->subtitle_st->time_base)*pkt->pts;
1440 len1 = avcodec_decode_subtitle(is->subtitle_st->codec,
1461 if (++is->subpq_windex == SUBPICTURE_QUEUE_SIZE)
1462 is->subpq_windex = 0;
1463 SDL_LockMutex(is->subpq_mutex);
1464 is->subpq_size++;
1465 SDL_UnlockMutex(is->subpq_mutex);
1477 static void update_sample_display(VideoState *is, short *samples, int samples_size)
1481 channels = is->audio_st->codec->channels;
1485 len = SAMPLE_ARRAY_SIZE - is->sample_array_index;
1488 memcpy(is->sample_array + is->sample_array_index, samples, len * sizeof(short));
1490 is->sample_array_index += len;
1491 if (is->sample_array_index >= SAMPLE_ARRAY_SIZE)
1492 is->sample_array_index = 0;
1499 static int synchronize_audio(VideoState *is, short *samples,
1505 n = 2 * is->audio_st->codec->channels;
1509 if (((is->av_sync_type == AV_SYNC_VIDEO_MASTER && is->video_st) ||
1510 is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) {
1514 ref_clock = get_master_clock(is);
1515 diff = get_audio_clock(is) - ref_clock;
1518 is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum;
1519 if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {
1521 is->audio_diff_avg_count++;
1524 avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);
1526 if (fabs(avg_diff) >= is->audio_diff_threshold) {
1527 wanted_size = samples_size + ((int)(diff * is->audio_st->codec->sample_rate) * n);
1560 is->audio_clock, is->video_clock, is->audio_diff_threshold);
1566 is->audio_diff_avg_count = 0;
1567 is->audio_diff_cum = 0;
1575 static int audio_decode_frame(VideoState *is, double *pts_ptr)
1577 AVPacket *pkt = &is->audio_pkt;
1578 AVCodecContext *dec= is->audio_st->codec;
1584 while (is->audio_pkt_size > 0) {
1585 data_size = sizeof(is->audio_buf1);
1587 (int16_t *)is->audio_buf1, &data_size,
1588 is->audio_pkt_data, is->audio_pkt_size);
1591 is->audio_pkt_size = 0;
1595 is->audio_pkt_data += len1;
1596 is->audio_pkt_size -= len1;
1600 if (dec->sample_fmt != is->audio_src_fmt) {
1601 if (is->reformat_ctx)
1602 av_audio_convert_free(is->reformat_ctx);
1603 is->reformat_ctx= av_audio_convert_alloc(SAMPLE_FMT_S16, 1,
1605 if (!is->reformat_ctx) {
1611 is->audio_src_fmt= dec->sample_fmt;
1614 if (is->reformat_ctx) {
1615 const void *ibuf[6]= {is->audio_buf1};
1616 void *obuf[6]= {is->audio_buf2};
1620 if (av_audio_convert(is->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) {
1624 is->audio_buf= is->audio_buf2;
1629 is->audio_buf= is->audio_buf1;
1633 pts = is->audio_clock;
1636 is->audio_clock += (double)data_size /
1642 is->audio_clock - last_clock,
1643 is->audio_clock, pts);
1644 last_clock = is->audio_clock;
1654 if (is->paused || is->audioq.abort_request) {
1659 if (packet_queue_get(&is->audioq, pkt, 1) < 0)
1666 is->audio_pkt_data = pkt->data;
1667 is->audio_pkt_size = pkt->size;
1671 is->audio_clock = av_q2d(is->audio_st->time_base)*pkt->pts;
1678 static int audio_write_get_buf_size(VideoState *is)
1680 return is->audio_buf_size - is->audio_buf_index;
1687 VideoState *is = opaque;
1694 if (is->audio_buf_index >= is->audio_buf_size) {
1695 audio_size = audio_decode_frame(is, &pts);
1698 is->audio_buf = is->audio_buf1;
1699 is->audio_buf_size = 1024;
1700 memset(is->audio_buf, 0, is->audio_buf_size);
1702 if (is->show_audio)
1703 update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
1704 audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
1706 is->audio_buf_size = audio_size;
1708 is->audio_buf_index = 0;
1710 len1 = is->audio_buf_size - is->audio_buf_index;
1713 memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
1716 is->audio_buf_index += len1;
1721 static int stream_component_open(VideoState *is, int stream_index)
1723 AVFormatContext *ic = is->ic;
1769 wanted_spec.userdata = is;
1774 is->audio_hw_buf_size = spec.size;
1775 is->audio_src_fmt= SAMPLE_FMT_S16;
1784 is->audio_stream = stream_index;
1785 is->audio_st = ic->streams[stream_index];
1786 is->audio_buf_size = 0;
1787 is->audio_buf_index = 0;
1790 is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
1791 is->audio_diff_avg_count = 0;
1794 is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / enc->sample_rate;
1796 memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
1797 packet_queue_init(&is->audioq);
1801 is->video_stream = stream_index;
1802 is->video_st = ic->streams[stream_index];
1804 is->frame_last_delay = 40e-3;
1805 is->frame_timer = (double)av_gettime() / 1000000.0;
1806 is->video_current_pts_time = av_gettime();
1808 packet_queue_init(&is->videoq);
1809 is->video_tid = SDL_CreateThread(video_thread, is);
1812 is->subtitle_stream = stream_index;
1813 is->subtitle_st = ic->streams[stream_index];
1814 packet_queue_init(&is->subtitleq);
1816 is->subtitle_tid = SDL_CreateThread(subtitle_thread, is);
1824 static void stream_component_close(VideoState *is, int stream_index)
1826 AVFormatContext *ic = is->ic;
1835 packet_queue_abort(&is->audioq);
1839 packet_queue_end(&is->audioq);
1840 if (is->reformat_ctx)
1841 av_audio_convert_free(is->reformat_ctx);
1844 packet_queue_abort(&is->videoq);
1848 SDL_LockMutex(is->pictq_mutex);
1849 SDL_CondSignal(is->pictq_cond);
1850 SDL_UnlockMutex(is->pictq_mutex);
1852 SDL_WaitThread(is->video_tid, NULL);
1854 packet_queue_end(&is->videoq);
1857 packet_queue_abort(&is->subtitleq);
1861 SDL_LockMutex(is->subpq_mutex);
1862 is->subtitle_stream_changed = 1;
1864 SDL_CondSignal(is->subpq_cond);
1865 SDL_UnlockMutex(is->subpq_mutex);
1867 SDL_WaitThread(is->subtitle_tid, NULL);
1869 packet_queue_end(&is->subtitleq);
1879 is->audio_st = NULL;
1880 is->audio_stream = -1;
1883 is->video_st = NULL;
1884 is->video_stream = -1;
1887 is->subtitle_st = NULL;
1888 is->subtitle_stream = -1;
1914 VideoState *is = arg;
1923 is->video_stream = -1;
1924 is->audio_stream = -1;
1925 is->subtitle_stream = -1;
1927 global_video_state = is;
1937 err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
1939 print_error(is->filename, err);
1943 is->ic = ic;
1950 fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
1968 is->filename, (double)timestamp / AV_TIME_BASE);
1993 dump_format(ic, 0, is->filename, 0);
1999 stream_component_open(is, audio_index);
2003 stream_component_open(is, video_index);
2006 is->show_audio = 1;
2010 stream_component_open(is, subtitle_index);
2013 if (is->video_stream < 0 && is->audio_stream < 0) {
2014 fprintf(stderr, "%s: could not open codecs\n", is->filename);
2020 if (is->abort_request)
2022 if (is->paused != is->last_paused) {
2023 is->last_paused = is->paused;
2024 if (is->paused)
2030 if (is->paused && !strcmp(ic->iformat->name, "rtsp")) {
2037 if (is->seek_req) {
2039 int64_t seek_target= is->seek_pos;
2041 if (is-> video_stream >= 0) stream_index= is-> video_stream;
2042 else if(is-> audio_stream >= 0) stream_index= is-> audio_stream;
2043 else if(is->subtitle_stream >= 0) stream_index= is->subtitle_stream;
2049 ret = av_seek_frame(is->ic, stream_index, seek_target, is->seek_flags);
2051 fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
2053 if (is->audio_stream >= 0) {
2054 packet_queue_flush(&is->audioq);
2055 packet_queue_put(&is->audioq, &flush_pkt);
2057 if (is->subtitle_stream >= 0) {
2058 packet_queue_flush(&is->subtitleq);
2059 packet_queue_put(&is->subtitleq, &flush_pkt);
2061 if (is->video_stream >= 0) {
2062 packet_queue_flush(&is->videoq);
2063 packet_queue_put(&is->videoq, &flush_pkt);
2066 is->seek_req = 0;
2070 if (is->audioq.size > MAX_AUDIOQ_SIZE ||
2071 is->videoq.size > MAX_VIDEOQ_SIZE ||
2072 is->subtitleq.size > MAX_SUBTITLEQ_SIZE) {
2081 pkt->stream_index= is->video_stream;
2082 packet_queue_put(&is->videoq, pkt);
2093 if (pkt->stream_index == is->audio_stream) {
2094 packet_queue_put(&is->audioq, pkt);
2095 } else if (pkt->stream_index == is->video_stream) {
2096 packet_queue_put(&is->videoq, pkt);
2097 } else if (pkt->stream_index == is->subtitle_stream) {
2098 packet_queue_put(&is->subtitleq, pkt);
2104 while (!is->abort_request) {
2114 if (is->audio_stream >= 0)
2115 stream_component_close(is, is->audio_stream);
2116 if (is->video_stream >= 0)
2117 stream_component_close(is, is->video_stream);
2118 if (is->subtitle_stream >= 0)
2119 stream_component_close(is, is->subtitle_stream);
2120 if (is->ic) {
2121 av_close_input_file(is->ic);
2122 is->ic = NULL; /* safety */
2130 event.user.data1 = is;
2138 VideoState *is;
2140 is = av_mallocz(sizeof(VideoState));
2141 if (!is)
2143 av_strlcpy(is->filename, filename, sizeof(is->filename));
2144 is->iformat = iformat;
2145 is->ytop = 0;
2146 is->xleft = 0;
2149 is->pictq_mutex = SDL_CreateMutex();
2150 is->pictq_cond = SDL_CreateCond();
2152 is->subpq_mutex = SDL_CreateMutex();
2153 is->subpq_cond = SDL_CreateCond();
2156 schedule_refresh(is, 40);
2158 is->av_sync_type = av_sync_type;
2159 is->parse_tid = SDL_CreateThread(decode_thread, is);
2160 if (!is->parse_tid) {
2161 av_free(is);
2164 return is;
2167 static void stream_close(VideoState *is)
2172 is->abort_request = 1;
2173 SDL_WaitThread(is->parse_tid, NULL);
2177 vp = &is->pictq[i];
2183 SDL_DestroyMutex(is->pictq_mutex);
2184 SDL_DestroyCond(is->pictq_cond);
2185 SDL_DestroyMutex(is->subpq_mutex);
2186 SDL_DestroyCond(is->subpq_cond);
2189 static void stream_cycle_channel(VideoState *is, int codec_type)
2191 AVFormatContext *ic = is->ic;
2196 start_index = is->video_stream;
2198 start_index = is->audio_stream;
2200 start_index = is->subtitle_stream;
2205 if (++stream_index >= is->ic->nb_streams)
2234 stream_component_close(is, start_index);
2235 stream_component_open(is, stream_index);
2259 /* if the stream is paused unpause it, then step */