summaryrefslogtreecommitdiff
path: root/mozilla-1645671.patch
blob: 8e9e31ecbcdec500c629f0cfa502714ebb17a269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
@@ -156,7 +156,7 @@
                                 MediaDataDecoder::DecodedData& aResults);
 
   void ReleaseUnusedVAAPIFrames();
-  DMABufSurfaceWrapper* GetUnusedDMABufSurfaceWrapper();
+  int GetUnusedDMABufSurfaceWrapperIndex();
   void ReleaseDMABufSurfaces();
 #endif
 
@@ -174,7 +174,7 @@
   const bool mDisableHardwareDecoding;
   VADisplay mDisplay;
   bool mUseDMABufSurfaces;
-  nsTArray<DMABufSurfaceWrapper> mDMABufSurfaces;
+  nsTArray<UniquePtr<DMABufSurfaceWrapper>> mDMABufSurfaces;
 #endif
   RefPtr<KnowsCompositor> mImageAllocator;
   RefPtr<ImageContainer> mImageContainer;
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -698,21 +698,20 @@
 void FFmpegVideoDecoder<LIBAV_VER>::ReleaseUnusedVAAPIFrames() {
   int len = mDMABufSurfaces.Length();
   for (int i = 0; i < len; i++) {
-    if (!mDMABufSurfaces[i].IsUsed()) {
-      mDMABufSurfaces[i].ReleaseVAAPIData();
+    if (!mDMABufSurfaces[i]->IsUsed()) {
+      mDMABufSurfaces[i]->ReleaseVAAPIData();
     }
   }
 }
 
-DMABufSurfaceWrapper*
-FFmpegVideoDecoder<LIBAV_VER>::GetUnusedDMABufSurfaceWrapper() {
+int FFmpegVideoDecoder<LIBAV_VER>::GetUnusedDMABufSurfaceWrapperIndex() {
   int len = mDMABufSurfaces.Length();
   for (int i = 0; i < len; i++) {
-    if (!mDMABufSurfaces[i].IsUsed()) {
-      return &(mDMABufSurfaces[i]);
+    if (!mDMABufSurfaces[i]->IsUsed()) {
+      return i;
     }
   }
-  return nullptr;
+  return -1;
 }
 
 void FFmpegVideoDecoder<LIBAV_VER>::ReleaseDMABufSurfaces() {
@@ -763,8 +762,8 @@
 
   RefPtr<DMABufSurfaceYUV> surface;
 
-  DMABufSurfaceWrapper* surfaceWrapper = GetUnusedDMABufSurfaceWrapper();
-  if (!surfaceWrapper) {
+  int surfaceWrapperIndex = GetUnusedDMABufSurfaceWrapperIndex();
+  if (surfaceWrapperIndex < 0) {
     if (mVAAPIDeviceContext) {
       surface = DMABufSurfaceYUV::CreateYUVSurface(vaDesc);
     } else {
@@ -776,16 +775,16 @@
       return MediaResult(NS_ERROR_OUT_OF_MEMORY,
                          RESULT_DETAIL("Unable to get DMABufSurfaceYUV"));
     }
-
 #  ifdef MOZ_LOGGING
     static int uid = 0;
     surface->SetUID(++uid);
     FFMPEG_LOG("Created new DMABufSurface UID = %d", uid);
 #  endif
-    mDMABufSurfaces.AppendElement(DMABufSurfaceWrapper(surface, mLib));
-    surfaceWrapper = &(mDMABufSurfaces[mDMABufSurfaces.Length() - 1]);
+    mDMABufSurfaces.AppendElement(
+        MakeUnique<DMABufSurfaceWrapper>(surface, mLib));
+    surfaceWrapperIndex = mDMABufSurfaces.Length() - 1;
   } else {
-    surface = surfaceWrapper->GetDMABufSurface();
+    surface = mDMABufSurfaces[surfaceWrapperIndex]->GetDMABufSurface();
     bool ret;
 
     if (mVAAPIDeviceContext) {
@@ -803,7 +802,7 @@
   }
 
   if (mVAAPIDeviceContext) {
-    surfaceWrapper->LockVAAPIData(mCodecContext, mFrame);
+    mDMABufSurfaces[surfaceWrapperIndex]->LockVAAPIData(mCodecContext, mFrame);
   }
 
   surface->SetYUVColorSpace(GetFrameColorSpace());

bgstack15