Bug 978647 - Properly handle EOF in DirectShow backend. r=edwin
authorChris Pearce <cpearce@mozilla.com>
Mon, 03 Mar 2014 19:57:10 +1300
changeset 171758 9401fbb063cb5466480f7de10f89a0207f3bcad6
parent 171757 855f10e178e8db567bca2646458235ea0cf683ca
child 171759 d30141d69df12cfe57aea30b6c81eb777edf1092
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersedwin
bugs978647
milestone30.0a1
Bug 978647 - Properly handle EOF in DirectShow backend. r=edwin
content/media/MediaResource.cpp
content/media/directshow/DirectShowReader.cpp
--- a/content/media/MediaResource.cpp
+++ b/content/media/MediaResource.cpp
@@ -1638,14 +1638,17 @@ public:
 
   RefPtr<MediaDecoder> mDecoder;
   int64_t mNumBytes;
   int64_t mOffset;
 };
 
 void BaseMediaResource::DispatchBytesConsumed(int64_t aNumBytes, int64_t aOffset)
 {
+  if (aNumBytes <= 0) {
+    return;
+  }
   RefPtr<nsIRunnable> event(new DispatchBytesConsumedEvent(mDecoder, aNumBytes, aOffset));
   NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
 }
 
 } // namespace mozilla
 
--- a/content/media/directshow/DirectShowReader.cpp
+++ b/content/media/directshow/DirectShowReader.cpp
@@ -79,16 +79,21 @@ ParseMP3Headers(MP3FrameParser *aParser,
   uint64_t offset = 0;
   while (aParser->NeedsData() && !aParser->ParsedHeaders()) {
     uint32_t bytesRead;
     char buffer[MAX_READ_SIZE];
     nsresult rv = aResource->ReadAt(offset, buffer,
                                     MAX_READ_SIZE, &bytesRead);
     NS_ENSURE_SUCCESS(rv, rv);
 
+    if (!bytesRead) {
+      // End of stream.
+      return NS_ERROR_FAILURE;
+    }
+
     aParser->Parse(buffer, bytesRead, offset);
     offset += bytesRead;
   }
 
   return aParser->IsMP3() ? NS_OK : NS_ERROR_FAILURE;
 }
 
 // Windows XP's MP3 decoder filter. This is available on XP only, on Vista