diff --git a/example/lib/packages/embedder_texture/page.dart b/example/lib/packages/embedder_texture/page.dart index 39e2718..6a1cd9e 100644 --- a/example/lib/packages/embedder_texture/page.dart +++ b/example/lib/packages/embedder_texture/page.dart @@ -31,16 +31,19 @@ class _EmbedderTexturePageState extends AppState { MediaQueryData media, AppLocalizations l10n, ) { + final width = MediaQuery.of(context).size.width; + final height = MediaQuery.of(context).size.height; + return BlockLayout( model: getIt(), title: widget.package.key, builder: (context, child, model) { - return const Padding( - padding: EdgeInsets.all(20), + return Padding( + padding: const EdgeInsets.all(20), child: Center( child: EmbedderTexture( - width: 320, - height: 240, + width: width, + height: height, ), ), ); diff --git a/packages/embedder_texture/aurora/camera.cpp b/packages/embedder_texture/aurora/camera.cpp index aa6d736..b8d3cee 100644 --- a/packages/embedder_texture/aurora/camera.cpp +++ b/packages/embedder_texture/aurora/camera.cpp @@ -26,19 +26,24 @@ void Camera::InitializeCamera(int cameraID) } } -void Camera::StartCapture() +Aurora::StreamCamera::CameraCapability Camera::StartCapture() { if (m_camera) { Aurora::StreamCamera::CameraInfo info; if (m_camera->getInfo(info)) { std::vector caps; - if (m_manager->queryCapabilities(info.id, caps)) { - m_camera->startCapture(caps.at(1)); + for(Aurora::StreamCamera::CameraCapability cap : caps) { + if (m_widthTexture + m_heightTexture < cap.width + cap.height) { + m_camera->startCapture(cap); + return cap; + } + } } } } + return Aurora::StreamCamera::CameraCapability{}; } void Camera::StopCapture() @@ -50,15 +55,22 @@ void Camera::StopCapture() } } -int64_t Camera::Register(int cameraID) +std::map Camera::Register(int cameraID, int width, int height) { + m_widthTexture = width; + m_heightTexture = height; + m_textureId = m_plugin->RegisterTexture( [this](size_t width, size_t height) { return this->m_buffer; }); InitializeCamera(cameraID); - StartCapture(); + auto cab = StartCapture(); - return m_textureId; + return std::map{ + {"textureId", m_textureId}, + {"width", cab.width}, + {"height", cab.height}, + }; } void Camera::Unregister() @@ -72,10 +84,18 @@ void Camera::onCameraFrame(std::shared_ptr if (buffer->handleType == Aurora::StreamCamera::HandleType::EGL) { // @todo Not tested. The device needs to be completed. auto eglImage = CameraEGLHelper::EGLCreateImage(buffer); - this->m_buffer = new TextureVariant(FlutterEGLImage{eglImage}); + this->m_buffer = new TextureVariant(FlutterEGLImage{ + eglImage, + buffer->width, + buffer->height, + }); } else { auto pixels = CameraPixelsHelper::YUVtoARGB(buffer->mapYCbCr()); - this->m_buffer = new TextureVariant(FlutterPixelBuffer{pixels}); + this->m_buffer = new TextureVariant(FlutterPixelBuffer{ + pixels, + buffer->width, + buffer->height, + }); } m_plugin->MarkTextureAvailable(m_textureId); @@ -83,7 +103,8 @@ void Camera::onCameraFrame(std::shared_ptr void Camera::onCameraError(const std::string &errorDescription) { - std::cout << "onCameraError" << std::endl; + this->Unregister(); + std::cout << errorDescription << std::endl; } void Camera::onCameraParameterChanged(Aurora::StreamCamera::CameraParameter parameter, diff --git a/packages/embedder_texture/aurora/camera_pixels_helper.cpp b/packages/embedder_texture/aurora/camera_pixels_helper.cpp index fb669fd..a9fea25 100644 --- a/packages/embedder_texture/aurora/camera_pixels_helper.cpp +++ b/packages/embedder_texture/aurora/camera_pixels_helper.cpp @@ -10,8 +10,8 @@ uint8_t *CameraPixelsHelper::YUVtoARGB(std::shared_ptry, - frame->cb, frame->cr, + frame->cb, frame->yStride, frame->cStride, frame->cStride, diff --git a/packages/embedder_texture/aurora/embedder_texture_plugin.cpp b/packages/embedder_texture/aurora/embedder_texture_plugin.cpp index bbe78b8..a5f8966 100644 --- a/packages/embedder_texture/aurora/embedder_texture_plugin.cpp +++ b/packages/embedder_texture/aurora/embedder_texture_plugin.cpp @@ -36,10 +36,12 @@ void EmbedderTexturePlugin::onMethodCall(const MethodCall &call) void EmbedderTexturePlugin::onCreate(const MethodCall &call) { auto cameraId = 0; + auto width = call.GetArgument("width"); + auto height = call.GetArgument("height"); - auto textureId = m_camera->Register(cameraId); + auto result = m_camera->Register(cameraId, width, height); - call.SendSuccessResponse(textureId); + call.SendSuccessResponse(result); } void EmbedderTexturePlugin::onRemove(const MethodCall &call) diff --git a/packages/embedder_texture/aurora/include/embedder_texture/camera.h b/packages/embedder_texture/aurora/include/embedder_texture/camera.h index d7d583e..b5aeeea 100644 --- a/packages/embedder_texture/aurora/include/embedder_texture/camera.h +++ b/packages/embedder_texture/aurora/include/embedder_texture/camera.h @@ -21,12 +21,12 @@ public: void onCameraParameterChanged(Aurora::StreamCamera::CameraParameter, const std::string &value) override; - int64_t Register(int cameraID); + std::map Register(int cameraID, int width, int height); void Unregister(); private: void InitializeCamera(int cameraID); - void StartCapture(); + Aurora::StreamCamera::CameraCapability StartCapture(); void StopCapture(); private: @@ -38,6 +38,9 @@ private: int m_cameraId = -1; int64_t m_textureId; + int m_widthTexture; + int m_heightTexture; + TextureVariant *m_buffer; }; diff --git a/packages/embedder_texture/lib/embedder_texture.dart b/packages/embedder_texture/lib/embedder_texture.dart index fc00a24..eeefffe 100644 --- a/packages/embedder_texture/lib/embedder_texture.dart +++ b/packages/embedder_texture/lib/embedder_texture.dart @@ -19,15 +19,19 @@ class EmbedderTexture extends StatefulWidget { class _EmbedderTextureState extends State { int _textureID = 0; + int _camera_width = 0; + int _camera_height = 0; @override initState() { super.initState(); EmbedderTexturePlatform.instance .create(widget.width, widget.height) - .then((value) => setState(() { + .then((data) => setState(() { if (mounted) { - _textureID = value!; + _textureID = data['textureId']!; + _camera_width = data['width']!; + _camera_height = data['height']!; debugPrint(_textureID.toString()); } })); @@ -42,11 +46,31 @@ class _EmbedderTextureState extends State { @override Widget build(BuildContext context) { if (_textureID != 0) { - return SizedBox( + + double w = 0; + double h = 0; + + if (MediaQuery.of(context).orientation == Orientation.portrait) { + w = _camera_width * widget.height / (widget.width - 40); + h = widget.width - 40; + } else { + w = _camera_height.toDouble(); + h = widget.height - 40 - 56; + } + + return Container( + color: Colors.black, width: widget.width, height: widget.height, child: Center( - child: Texture(textureId: _textureID) + child: RotationTransition( + turns: AlwaysStoppedAnimation(MediaQuery.of(context).orientation == Orientation.portrait ? 90 / 360 : 0), + child: SizedBox( + width: w, + height: h, + child: Texture(textureId: _textureID) + ), + ) ), ); } diff --git a/packages/embedder_texture/lib/embedder_texture_method_channel.dart b/packages/embedder_texture/lib/embedder_texture_method_channel.dart index c7513a9..d5a455d 100644 --- a/packages/embedder_texture/lib/embedder_texture_method_channel.dart +++ b/packages/embedder_texture/lib/embedder_texture_method_channel.dart @@ -10,12 +10,12 @@ class MethodChannelEmbedderTexture extends EmbedderTexturePlatform { final methodChannel = const MethodChannel('embedder_texture'); @override - Future create(double width, double height) async { - final version = await methodChannel.invokeMethod('create', { - 'width': width, - 'height': height, + Future> create(double width, double height) async { + final data = await methodChannel.invokeMethod?>('create', { + 'width': width.round(), + 'height': height.round(), }); - return version; + return data ?? {}; } @override diff --git a/packages/embedder_texture/lib/embedder_texture_platform_interface.dart b/packages/embedder_texture/lib/embedder_texture_platform_interface.dart index d120c4e..f06ad88 100644 --- a/packages/embedder_texture/lib/embedder_texture_platform_interface.dart +++ b/packages/embedder_texture/lib/embedder_texture_platform_interface.dart @@ -23,7 +23,7 @@ abstract class EmbedderTexturePlatform extends PlatformInterface { _instance = instance; } - Future create(double width, double height) { + Future> create(double width, double height) { throw UnimplementedError('create() has not been implemented.'); }