मैं इसी मुद्दे पर आया और मैं जिस समाधान का उपयोग करता हूं वह ईजीएल के माध्यम से टाइमस्टैम्प सेट करना है, RecordFBOActivity#doFrame के समान। ऐसा करने के लिए एक मध्यवर्ती आवंटन का उपयोग रेंडरस्क्रिप्ट और ओपनजीएल/ईजीएल के बीच के अंतर को पुल करने के लिए किया जाता है।
चलिए डेटा प्रवाह को चरणों के साथ प्रसंस्करण पाइपलाइन के रूप में देखते हैं।
मूल पाइपलाइन
[Camera]
--> [ImageAllocation]
--> [RenderScript]
--> [MediaCodecSurfaceAllocationForEncoder]
--> [MediaCodec]
मूल पाइपलाइन में सभी बफ़र्स रुपये आवंटन कर रहे हैं।
MediaCodecSurfaceAllocation
एन्कोडर से लौटाई गई सतह पर आधारित है, यानी MediaCodec#getSurface()
।
नई पाइपलाइन
[Camera]
--> [ImageAllocation]
--> [RenderScript]
--> [IntermediateAllocation]
--> [EglWindowSurfaceForEncoder]
--> [MediaCodec]
नई पाइपलाइन में दो बड़े बदलाव, IntermediateAllocation
और EglWindowSurfaceForEncoder
IntermediateAllocation
है एक SurfaceTexture आधारित आवंटन, ful स्क्रीन बनावट CameraCaptureActivity में इस्तेमाल blitter के समान नहीं है।
EglWindowSurfaceForEncoder
RecordFBOActivity#startEncoder
को एनकोडर के इनपुट सतह, समान लपेटता कुंजी यहाँ अपने खुद के OnFrameAvailableListener स्थापित करने के लिए है।
सेटअप कोड
void setup() {
mEglWindowSurfaceForEncoder= new WindowSurface(mEglCore, encoderCore.getInputSurface(), true);
mFullScreen = new FullFrameRect(
new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
mTextureId = mFullScreen.createTextureObject();
mSurfaceTexture = new SurfaceTexture(mTextureId);
Type renderType = new Type.Builder(renderScript, Element.RGBA_8888(renderScript))
.setX(width)
.setY(height)
.create();
mIntermediateAllocation = Allocation.createTyped(
renderScript,
renderType,
Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT);
mIntermediateAllocation .setSurface(surface);
mAllocationFromCamera = ...
}
OnNewCameraImage
mIntermediateAllocation.copyFrom(mAllocationFromCamera);
OnFrameAvailableListener
mSurfaceTexture.setOnFrameAvailableListener(
new SurfaceTexture.OnFrameAvailableListener() {
public void onFrameAvailableListener(SurfaceTexture) {
//latch the image data from camera
mSurfaceTexture.updateTexImage();
// Draw the frame.
mSurfaceTexture.getTransformMatrix(mSTMatrix);
mFullScreen.drawFrame(mTextureId, mSTMatrix);
// latch frame to encoder input
mEglWindowSurfaceForEncoder.setPresentationTimes(timestampNanos);
mEglWindowSurfaceForEncoder.swapBuffers();
}
}
}
उपर्युक्त कोड ईजीएल संदर्भ में चलाना चाहिए (यानी ओपनजीएल प्रतिपादन धागे पर)।