+static int adts_aac_resync(AVFormatContext *s)
+{
+ uint16_t state;
+
+ // skip data until an ADTS frame is found
+ state = avio_r8(s->pb);
+ while (!avio_feof(s->pb) && avio_tell(s->pb) < s->probesize) {
+ state = (state << 8) | avio_r8(s->pb);
+ if ((state >> 4) != 0xFFF)
+ continue;
+ avio_seek(s->pb, -2, SEEK_CUR);
+ break;
+ }
+ if (s->pb->eof_reached)
+ return AVERROR_EOF;
+ if ((state >> 4) != 0xFFF)
+ return AVERROR_INVALIDDATA;
+
+ return 0;
+}
+