comparison utils.c @ 2018:0d9b233dff9b libavformat

DVR-MS probe audio format patch by John Donaghy \ johnfdonaghy chez gmail dot com / Original thread: date: 03/13/2007 04:56 PM subject: [Ffmpeg-devel] [PATCH] DVR-MS probe audio format - was DVR-MS bug (MP2 decoding)
author benoit
date Thu, 12 Apr 2007 08:11:33 +0000
parents 1a3c9056982a
children d0d39f124c6b
comparison
equal deleted inserted replaced
2017:6c6eb1bac2f3 2018:0d9b233dff9b
1639 } 1639 }
1640 fail: 1640 fail:
1641 return ret; 1641 return ret;
1642 } 1642 }
1643 1643
1644 static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
1645 {
1646 AVInputFormat *fmt;
1647 fmt = av_probe_input_format2(pd, 1, &score);
1648
1649 if (fmt) {
1650 if (strncmp(fmt->name, "mp3", 3) == 0)
1651 st->codec->codec_id = CODEC_ID_MP3;
1652 else if (strncmp(fmt->name, "ac3", 3) == 0)
1653 st->codec->codec_id = CODEC_ID_AC3;
1654 }
1655 return fmt;
1656 }
1657
1644 /* absolute maximum size we read until we abort */ 1658 /* absolute maximum size we read until we abort */
1645 #define MAX_READ_SIZE 5000000 1659 #define MAX_READ_SIZE 5000000
1646 1660
1647 #define MAX_STD_TIMEBASES (60*12+5) 1661 #define MAX_STD_TIMEBASES (60*12+5)
1648 static int get_std_framerate(int i){ 1662 static int get_std_framerate(int i){
1660 int duration_count[MAX_STREAMS]={0}; 1674 int duration_count[MAX_STREAMS]={0};
1661 double (*duration_error)[MAX_STD_TIMEBASES]; 1675 double (*duration_error)[MAX_STD_TIMEBASES];
1662 offset_t old_offset = url_ftell(&ic->pb); 1676 offset_t old_offset = url_ftell(&ic->pb);
1663 int64_t codec_info_duration[MAX_STREAMS]={0}; 1677 int64_t codec_info_duration[MAX_STREAMS]={0};
1664 int codec_info_nb_frames[MAX_STREAMS]={0}; 1678 int codec_info_nb_frames[MAX_STREAMS]={0};
1679 AVProbeData probe_data[MAX_STREAMS];
1680 int codec_identified[MAX_STREAMS]={0};
1665 1681
1666 duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error)); 1682 duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error));
1667 if (!duration_error) return AVERROR_NOMEM; 1683 if (!duration_error) return AVERROR_NOMEM;
1668 1684
1669 for(i=0;i<ic->nb_streams;i++) { 1685 for(i=0;i<ic->nb_streams;i++) {
1685 1701
1686 for(i=0;i<MAX_STREAMS;i++){ 1702 for(i=0;i<MAX_STREAMS;i++){
1687 last_dts[i]= AV_NOPTS_VALUE; 1703 last_dts[i]= AV_NOPTS_VALUE;
1688 } 1704 }
1689 1705
1706 memset(probe_data, 0, sizeof(probe_data));
1690 count = 0; 1707 count = 0;
1691 read_size = 0; 1708 read_size = 0;
1692 ppktl = &ic->packet_buffer; 1709 ppktl = &ic->packet_buffer;
1693 for(;;) { 1710 for(;;) {
1694 /* check if one codec still needs to be handled */ 1711 /* check if one codec still needs to be handled */
1700 if( (st->codec->time_base.den >= 101LL*st->codec->time_base.num || st->codec->codec_id == CODEC_ID_MPEG2VIDEO) 1717 if( (st->codec->time_base.den >= 101LL*st->codec->time_base.num || st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
1701 && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO) 1718 && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO)
1702 break; 1719 break;
1703 if(st->parser && st->parser->parser->split && !st->codec->extradata) 1720 if(st->parser && st->parser->parser->split && !st->codec->extradata)
1704 break; 1721 break;
1722 if (st->codec->codec_type == CODEC_TYPE_AUDIO &&
1723 st->codec->codec_id == CODEC_ID_NONE)
1724 break;
1705 } 1725 }
1706 if (i == ic->nb_streams) { 1726 if (i == ic->nb_streams) {
1707 /* NOTE: if the format has no header, then we need to read 1727 /* NOTE: if the format has no header, then we need to read
1708 some packets to get most of the streams, so we cannot 1728 some packets to get most of the streams, so we cannot
1709 stop here */ 1729 stop here */
1785 } 1805 }
1786 duration_count[index]++; 1806 duration_count[index]++;
1787 } 1807 }
1788 if(last == AV_NOPTS_VALUE || duration_count[index]<=1) 1808 if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
1789 last_dts[pkt->stream_index]= pkt->dts; 1809 last_dts[pkt->stream_index]= pkt->dts;
1810
1811 if (st->codec->codec_id == CODEC_ID_NONE) {
1812 AVProbeData *pd = &(probe_data[st->index]);
1813 pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size);
1814 memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
1815 pd->buf_size += pkt->size;
1816 }
1790 } 1817 }
1791 if(st->parser && st->parser->parser->split && !st->codec->extradata){ 1818 if(st->parser && st->parser->parser->split && !st->codec->extradata){
1792 int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); 1819 int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
1793 if(i){ 1820 if(i){
1794 st->codec->extradata_size= i; 1821 st->codec->extradata_size= i;
1864 st->r_frame_rate.num = st->time_base.den; 1891 st->r_frame_rate.num = st->time_base.den;
1865 st->r_frame_rate.den = st->time_base.num; 1892 st->r_frame_rate.den = st->time_base.num;
1866 } 1893 }
1867 } 1894 }
1868 }else if(st->codec->codec_type == CODEC_TYPE_AUDIO) { 1895 }else if(st->codec->codec_type == CODEC_TYPE_AUDIO) {
1896 if (st->codec->codec_id == CODEC_ID_NONE) {
1897 codec_identified[st->index] = set_codec_from_probe_data(st, &(probe_data[st->index]), 0);
1898 if (codec_identified[st->index]) {
1899 st->need_parsing = 1;
1900 }
1901 }
1869 if(!st->codec->bits_per_sample) 1902 if(!st->codec->bits_per_sample)
1870 st->codec->bits_per_sample= av_get_bits_per_sample(st->codec->codec_id); 1903 st->codec->bits_per_sample= av_get_bits_per_sample(st->codec->codec_id);
1871 } 1904 }
1872 } 1905 }
1873 1906
1874 av_estimate_timings(ic, old_offset); 1907 av_estimate_timings(ic, old_offset);
1908
1909 for(i=0;i<ic->nb_streams;i++) {
1910 st = ic->streams[i];
1911 if (codec_identified[st->index]) {
1912 av_read_frame_flush(ic);
1913 av_seek_frame(ic, st->index, 0.0, 0);
1914 url_fseek(&ic->pb, ic->data_offset, SEEK_SET);
1915 }
1916 }
1917
1875 #if 0 1918 #if 0
1876 /* correct DTS for b frame streams with no timestamps */ 1919 /* correct DTS for b frame streams with no timestamps */
1877 for(i=0;i<ic->nb_streams;i++) { 1920 for(i=0;i<ic->nb_streams;i++) {
1878 st = ic->streams[i]; 1921 st = ic->streams[i];
1879 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { 1922 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
1896 } 1939 }
1897 } 1940 }
1898 #endif 1941 #endif
1899 1942
1900 av_free(duration_error); 1943 av_free(duration_error);
1944 for(i=0;i<MAX_STREAMS;i++){
1945 av_freep(&(probe_data[i].buf));
1946 }
1901 1947
1902 return ret; 1948 return ret;
1903 } 1949 }
1904 1950
1905 /*******************************************************/ 1951 /*******************************************************/