Bug 978647 - Properly handle EOF in DirectShow backend. r=edwin a=sylvestre
authorChris Pearce <cpearce@mozilla.com>
Tue, 04 Mar 2014 11:24:45 +1300
changeset 183121 9745afb973d2e528c3ef349f82aa86791f1a226f
parent 183120 f6ed13594ecdb5f3a10f0c0ad0de8a83f3d693bf
child 183122 8fcb138f311b9e2a314ed3618c860208340bc0b4
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin, sylvestre
bugs978647
milestone29.0a2
Bug 978647 - Properly handle EOF in DirectShow backend. r=edwin a=sylvestre
content/media/MediaResource.cpp
content/media/directshow/DirectShowReader.cpp
--- a/content/media/MediaResource.cpp
+++ b/content/media/MediaResource.cpp
@@ -1616,14 +1616,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
@@ -78,16 +78,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