Skip to content

Commit d3df6f2

Browse files
Merge mozilla-central to mozilla-inbound
2 parents df263f0 + 594937f commit d3df6f2

File tree

10 files changed

+13849
-13972
lines changed

10 files changed

+13849
-13972
lines changed

dom/media/encoder/VP8TrackEncoder.cpp

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ LazyLogModule gVP8TrackEncoderLog("VP8TrackEncoder");
2828

2929
using namespace mozilla::gfx;
3030
using namespace mozilla::layers;
31+
using namespace mozilla::media;
32+
33+
static already_AddRefed<SourceSurface>
34+
GetSourceSurface(already_AddRefed<Image> aImg)
35+
{
36+
RefPtr<Image> img = aImg;
37+
if (!img) {
38+
return nullptr;
39+
}
40+
41+
if (!img->AsGLImage() || NS_IsMainThread()) {
42+
RefPtr<SourceSurface> surf = img->GetAsSourceSurface();
43+
return surf.forget();
44+
}
45+
46+
// GLImage::GetAsSourceSurface() only supports main thread
47+
RefPtr<SourceSurface> surf;
48+
RefPtr<Runnable> runnable = NewRunnableFrom([img, &surf]() -> nsresult {
49+
surf = img->GetAsSourceSurface();
50+
return NS_OK;
51+
});
52+
53+
NS_DispatchToMainThread(runnable, NS_DISPATCH_SYNC);
54+
return surf.forget();
55+
}
3156

3257
VP8TrackEncoder::VP8TrackEncoder(TrackRate aTrackRate)
3358
: VideoTrackEncoder(aTrackRate)
@@ -433,37 +458,6 @@ nsresult VP8TrackEncoder::PrepareRawFrame(VideoChunk &aChunk)
433458
return NS_OK;
434459
}
435460

436-
void
437-
VP8TrackEncoder::ReplyGetSourceSurface(already_AddRefed<gfx::SourceSurface> aSurf)
438-
{
439-
mSourceSurface = aSurf;
440-
}
441-
442-
already_AddRefed<gfx::SourceSurface>
443-
VP8TrackEncoder::GetSourceSurface(already_AddRefed<Image> aImg)
444-
{
445-
RefPtr<Image> img = aImg;
446-
mSourceSurface = nullptr;
447-
if (img) {
448-
if (img->AsGLImage() && !NS_IsMainThread()) {
449-
// GLImage::GetAsSourceSurface() only support main thread
450-
RefPtr<Runnable> getsourcesurface_runnable =
451-
media::NewRunnableFrom([this, img]() -> nsresult {
452-
// Due to the parameter DISPATCH_SYNC, encoder thread will stock at
453-
// MediaRecorder::Session::Extract(bool). There is no chance
454-
// that TrackEncoder will be destroyed during this period. So
455-
// there is no need to use RefPtr to hold TrackEncoder.
456-
ReplyGetSourceSurface(img->GetAsSourceSurface());
457-
return NS_OK;
458-
});
459-
NS_DispatchToMainThread(getsourcesurface_runnable, NS_DISPATCH_SYNC);
460-
} else {
461-
mSourceSurface = img->GetAsSourceSurface();
462-
}
463-
}
464-
return mSourceSurface.forget();
465-
}
466-
467461
// These two define value used in GetNextEncodeOperation to determine the
468462
// EncodeOperation for next target frame.
469463
#define I_FRAME_RATIO (0.5)

dom/media/encoder/VP8TrackEncoder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class VP8TrackEncoder : public VideoTrackEncoder
3636

3737
nsresult GetEncodedTrack(EncodedFrameContainer& aData) final override;
3838

39-
void ReplyGetSourceSurface(already_AddRefed<gfx::SourceSurface> aSurf);
4039
protected:
4140
nsresult Init(int32_t aWidth, int32_t aHeight,
4241
int32_t aDisplayWidth, int32_t aDisplayHeight) final override;
@@ -61,8 +60,6 @@ class VP8TrackEncoder : public VideoTrackEncoder
6160
// Prepare the input data to the mVPXImageWrapper for encoding.
6261
nsresult PrepareRawFrame(VideoChunk &aChunk);
6362

64-
already_AddRefed<gfx::SourceSurface> GetSourceSurface(already_AddRefed<layers::Image> aImg);
65-
6663
// Output frame rate.
6764
uint32_t mEncodedFrameRate;
6865
// Duration for the output frame, reciprocal to mEncodedFrameRate.
@@ -91,7 +88,6 @@ class VP8TrackEncoder : public VideoTrackEncoder
9188
nsAutoPtr<vpx_codec_ctx_t> mVPXContext;
9289
// Image Descriptor.
9390
nsAutoPtr<vpx_image_t> mVPXImageWrapper;
94-
RefPtr<gfx::SourceSurface> mSourceSurface;
9591
};
9692

9793
} // namespace mozilla

0 commit comments

Comments
 (0)