Bug 567077 - Avoid sniffing when recreating a channel. r=cpearce

This commit is contained in:
Paul Adenot 2012-09-04 16:24:12 -07:00
parent 5a71dd81e5
commit 4283006604
3 changed files with 41 additions and 10 deletions

View File

@ -312,6 +312,11 @@ public:
static bool IsMediaPluginsType(const nsACString& aType);
#endif
/**
* Get the mime type for this element.
*/
void GetMimeType(nsCString& aMimeType);
/**
* Called when a child source element is added to this media element. This
* may queue a task to run the select resource algorithm if appropriate.
@ -872,6 +877,13 @@ protected:
// True if the media's channel's download has been suspended.
bool mDownloadSuspendedByCache;
// The Content-Type for this media. When we are sniffing for the Content-Type,
// and we are recreating a channel after the initial load, we need that
// information to give it as a hint to the channel for it to bypass the
// sniffing phase, that would fail because sniffing only works when applied to
// the first bytes of the stream.
nsCString mMimeType;
};
#endif

View File

@ -2434,19 +2434,21 @@ nsresult nsHTMLMediaElement::InitializeDecoderForChannel(nsIChannel *aChannel,
NS_ASSERTION(mDecoder == nullptr, "Shouldn't have a decoder");
nsAutoCString mimeType;
aChannel->GetContentType(mimeType);
nsRefPtr<nsMediaDecoder> decoder = CreateDecoder(mimeType);
aChannel->GetContentType(mMimeType);
NS_ASSERTION(!mMimeType.IsEmpty(), "We should have the Content-Type.");
nsRefPtr<nsMediaDecoder> decoder = CreateDecoder(mMimeType);
if (!decoder) {
nsAutoString src;
GetCurrentSrc(src);
NS_ConvertUTF8toUTF16 mimeUTF16(mimeType);
NS_ConvertUTF8toUTF16 mimeUTF16(mMimeType);
const PRUnichar* params[] = { mimeUTF16.get(), src.get() };
ReportLoadError("MediaLoadUnsupportedMimeType", params, ArrayLength(params));
return NS_ERROR_FAILURE;
}
LOG(PR_LOG_DEBUG, ("%p Created decoder %p for type %s", this, decoder.get(), mimeType.get()));
LOG(PR_LOG_DEBUG, ("%p Created decoder %p for type %s", this, decoder.get(), mMimeType.get()));
MediaResource* resource = MediaResource::Create(decoder, aChannel);
if (!resource)
@ -3529,6 +3531,11 @@ NS_IMETHODIMP nsHTMLMediaElement::GetMozFragmentEnd(double *aTime)
return NS_OK;
}
void nsHTMLMediaElement::GetMimeType(nsCString& aMimeType)
{
aMimeType = mMimeType;
}
void nsHTMLMediaElement::NotifyAudioAvailableListener()
{
if (mDecoder) {

View File

@ -704,12 +704,24 @@ ChannelMediaResource::RecreateChannel()
nsCOMPtr<nsILoadGroup> loadGroup = element->GetDocumentLoadGroup();
NS_ENSURE_TRUE(loadGroup, NS_ERROR_NULL_POINTER);
return NS_NewChannel(getter_AddRefs(mChannel),
mURI,
nullptr,
loadGroup,
nullptr,
loadFlags);
nsresult rv = NS_NewChannel(getter_AddRefs(mChannel),
mURI,
nsnull,
loadGroup,
nsnull,
loadFlags);
// We have cached the Content-Type, which should not change. Give a hint to
// the channel to avoid a sniffing failure, which would be expected because we
// are probably seeking in the middle of the bitstream, and sniffing relies
// on the presence of a magic number at the beginning of the stream.
nsCAutoString contentType;
element->GetMimeType(contentType);
NS_ASSERTION(!contentType.IsEmpty(),
"When recreating a channel, we should know the Content-Type.");
mChannel->SetContentType(contentType);
return rv;
}
void