/** * If this stream is an MP3, we want to parse the headers to estimate the * stream duration. */ nsresult GStreamerReader::ParseMP3Headers() { MediaResource *resource = mDecoder->GetResource(); const uint32_t MAX_READ_BYTES = 4096; uint64_t offset = 0; char bytes[MAX_READ_BYTES]; uint32_t bytesRead; do { nsresult rv = resource->ReadAt(offset, bytes, MAX_READ_BYTES, &bytesRead); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(bytesRead, NS_ERROR_FAILURE); mMP3FrameParser.Parse(bytes, bytesRead, offset); offset += bytesRead; } while (!mMP3FrameParser.ParsedHeaders()); if (mMP3FrameParser.IsMP3()) { mLastParserDuration = mMP3FrameParser.GetDuration(); mDataOffset = mMP3FrameParser.GetMP3Offset(); // Update GStreamer's stream length in case we found any ID3 headers to // ignore. gst_app_src_set_size(mSource, GetDataLength()); } return NS_OK; }
/** * If this stream is an MP3, we want to parse the headers to estimate the * stream duration. */ nsresult GStreamerReader::ParseMP3Headers() { MediaResource *resource = mDecoder->GetResource(); const uint32_t MAX_READ_BYTES = 4096; uint64_t offset = 0; char bytes[MAX_READ_BYTES]; uint32_t bytesRead; do { nsresult rv = resource->ReadAt(offset, bytes, MAX_READ_BYTES, &bytesRead); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(bytesRead, NS_ERROR_FAILURE); mMP3FrameParser.Parse(bytes, bytesRead, offset); offset += bytesRead; } while (!mMP3FrameParser.ParsedHeaders()); if (mMP3FrameParser.IsMP3()) { mLastParserDuration = mMP3FrameParser.GetDuration(); } return NS_OK; }