| 1943 | } |
| 1944 | |
| 1945 | static int store_icy(URLContext *h, int size) |
| 1946 | { |
| 1947 | HTTPContext *s = h->priv_data; |
| 1948 | /* until next metadata packet */ |
| 1949 | uint64_t remaining; |
| 1950 | |
| 1951 | if (s->icy_metaint < s->icy_data_read) |
| 1952 | return AVERROR_INVALIDDATA; |
| 1953 | remaining = s->icy_metaint - s->icy_data_read; |
| 1954 | |
| 1955 | if (!remaining) { |
| 1956 | /* The metadata packet is variable sized. It has a 1 byte header |
| 1957 | * which sets the length of the packet (divided by 16). If it's 0, |
| 1958 | * the metadata doesn't change. After the packet, icy_metaint bytes |
| 1959 | * of normal data follows. */ |
| 1960 | uint8_t ch; |
| 1961 | int len = http_read_stream_all(h, &ch, 1); |
| 1962 | if (len < 0) |
| 1963 | return len; |
| 1964 | if (ch > 0) { |
| 1965 | char data[255 * 16 + 1]; |
| 1966 | int ret; |
| 1967 | len = ch * 16; |
| 1968 | ret = http_read_stream_all(h, data, len); |
| 1969 | if (ret < 0) |
| 1970 | return ret; |
| 1971 | data[len] = 0; |
| 1972 | if ((ret = av_opt_set(s, "icy_metadata_packet", data, 0)) < 0) |
| 1973 | return ret; |
| 1974 | update_metadata(h, data); |
| 1975 | } |
| 1976 | s->icy_data_read = 0; |
| 1977 | remaining = s->icy_metaint; |
| 1978 | } |
| 1979 | |
| 1980 | return FFMIN(size, remaining); |
| 1981 | } |
| 1982 | |
| 1983 | static int http_read(URLContext *h, uint8_t *buf, int size) |
| 1984 | { |
no test coverage detected