/** * Create() allocates an image data resource with the given format and size. * * For security reasons, if uninitialized, the bitmap will not contain random * memory, but may contain data from a previous image produced by the same * module if the bitmap was cached and re-used. * * @param[in] instance A <code>PP_Instance</code> identifying one instance * of a module. * @param[in] format The desired image data format. * @param[in] size A pointer to a <code>PP_Size</code> containing the image * size. * @param[in] init_to_zero A <code>PP_Bool</code> to determine transparency * at creation. * Set the <code>init_to_zero</code> flag if you want the bitmap initialized * to transparent during the creation process. If this flag is not set, the * current contents of the bitmap will be undefined, and the module should * be sure to set all the pixels. * * @return A <code>PP_Resource</code> with a nonzero ID on success or zero on * failure. Failure means the instance, image size, or format was invalid. */ public static PPResource Create(PPInstance instance, PPImageDataFormat format, PPSize size, PPBool init_to_zero) { return(_Create(instance, format, size, init_to_zero)); }
extern static int _Initialize(PPResource video_encoder, PPVideoFrameFormat input_format, PPSize input_visible_size, PPVideoProfile output_profile, uint initial_bitrate, PPHardwareAcceleration acceleration, PPCompletionCallback callback);
/// <summary> /// Initializes a video encoder resource asynchronously. This should be called after /// GetSupportedProfiles() and before any functions below. /// </summary> /// <param name="inputFormat">The <code>VideoFrame_Format</code> of the /// frames which will be encoded.</param> /// <param name="inputVisibleSize">A <code>Size</code> specifying the /// dimensions of the visible part of the input frames.</param> /// <param name="outputProfile">A <code>VideoProfile</code> specifying the /// codec profile of the encoded output stream.</param> /// <param name="initialBitrate">The initial bitrate of the encoded output stream</param> /// <param name="acceleration">A <code>HardwareAcceleration</code> specifying /// whether to use a hardware accelerated or a software implementation.</param> /// <param name="messageLoop">Optional MessageLoop instance that can be used to post the command to</param> /// <returns>Error code. Returns NotSupported if video encoding is not available, or the /// requested codec profile is not supported. /// Returns NoMemory if frame and bitstream buffers can't be created.</returns> public Task <PPError> InitializeAsync(VideoFrameFormat inputFormat, PPSize inputVisibleSize, VideoProfile outputProfile, uint initialBitrate, HardwareAcceleration acceleration, MessageLoop messageLoop = null) => InitializeAsyncCore(inputFormat, inputVisibleSize, outputProfile, initialBitrate, acceleration, messageLoop);
/// <summary> /// A constructor allocating a new 2D graphics context with the given size /// in the browser, resulting object will be IsEmpty if the allocation /// failed. /// /// </summary> /// <param name="instance">The instance with which this resource will be associated.</param> /// <param name="size">The size of the 2D graphics context in the browser, measured in pixels. See <code>Scale</code> for more information.</param> /// <param name="isAlwaysOpaque">Set the <code>isAlwaysOpaque</code> flag /// to true if you know that you will be painting only opaque data to this /// context. This option will disable blending when compositing the module /// with the web page, which might give higher performance on some computers. /// /// If you set <code>isAlwaysOpaque</code>, your alpha channel should /// always be set to 0xFF or there may be painting artifacts. The alpha values /// overwrite the destination alpha values without blending when /// <code>isAlwaysOpaque</code> is true. /// </param> public Graphics2D(Instance instance, PPSize size, bool isAlwaysOpaque) { handle = PPBGraphics2D.Create(instance, size, (isAlwaysOpaque) ? PPBool.True : PPBool.False); if (!handle.IsEmpty) { Size = size; } }
/// <summary> /// Initializes a video encoder resource. This should be called after /// GetSupportedProfiles() and before any functions below. /// </summary> /// <param name="inputFormat">The <code>VideoFrame_Format</code> of the /// frames which will be encoded.</param> /// <param name="inputVisibleSize">A <code>Size</code> specifying the /// dimensions of the visible part of the input frames.</param> /// <param name="outputProfile">A <code>VideoProfile</code> specifying the /// codec profile of the encoded output stream.</param> /// <param name="initialBitrate">The initial bitrate of the encoded output stream</param> /// <param name="acceleration">A <code>HardwareAcceleration</code> specifying /// whether to use a hardware accelerated or a software implementation.</param> /// <returns>Error code. Returns NotSupported if video encoding is not available, or the /// requested codec profile is not supported. /// Returns NoMemory if frame and bitstream buffers can't be created.</returns> public PPError Initialize(VideoFrameFormat inputFormat, PPSize inputVisibleSize, VideoProfile outputProfile, uint initialBitrate, HardwareAcceleration acceleration) => (PPError)PPBVideoEncoder.Initialize(this, (PPVideoFrameFormat)inputFormat, inputVisibleSize, (PPVideoProfile)outputProfile, initialBitrate, (PPHardwareAcceleration)acceleration, new CompletionCallback(OnInitialize));
/// <summary> /// A constructor that allocates a new <code>ImageData</code> in the browser /// with the provided parameters. The resulting object will be IsEmpty if /// the allocation failed. /// </summary> /// <param name="instance">The instance with which this resource will be /// associated. /// </param> /// <param name="format">A PP_ImageDataFormat containing desired image format. /// PP_ImageDataFormat is an enumeration of the different types of /// image data formats. /// </param> /// <param name="size">the image size.</param> /// <param name="init_to_zero">A bool used to determine transparency at /// creation. Set the <code>init_to_zero</code> flag if you want the bitmap /// initialized to transparent during the creation process. If this flag is /// not set, the current contents of the bitmap will be undefined, and the /// module should be sure to set all the pixels. /// </param> public ImageData(Instance instance, PPImageDataFormat format, PPSize size, bool init_to_zero) { handle = PPBImageData.Create(instance, format, size, init_to_zero ? PPBool.True : PPBool.False); if (PPBImageData.IsImageData(handle) == PPBool.True) { InitData(); } }
public override bool Equals(object obj) { if (!(obj is PPSize)) { return(false); } PPSize comp = (PPSize)obj; return((comp.width == this.width) && (comp.height == this.height)); }
private async Task <PPError> InitializeAsyncCore(VideoFrameFormat inputFormat, PPSize inputVisibleSize, VideoProfile outputProfile, uint initialBitrate, HardwareAcceleration acceleration, MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleInitialize += handler; if (MessageLoop == null && messageLoop == null) { Initialize(inputFormat, inputVisibleSize, outputProfile, initialBitrate, acceleration); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBVideoEncoder.Initialize(this, (PPVideoFrameFormat)inputFormat, inputVisibleSize, (PPVideoProfile)outputProfile, initialBitrate, (PPHardwareAcceleration)acceleration, new BlockUntilComplete() ); tcs.TrySetResult(result); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(PPError.Aborted); } finally { HandleInitialize -= handler; } }
/** * Initializes a video encoder resource. The plugin should call Initialize() * successfully before calling any of the functions below. * * @param[in] video_encoder A <code>PP_Resource</code> identifying the video * encoder. * @param[in] input_format The <code>PP_VideoFrame_Format</code> of the * frames which will be encoded. * @param[in] input_visible_size A <code>PP_Size</code> specifying the * dimensions of the visible part of the input frames. * @param[in] output_profile A <code>PP_VideoProfile</code> specifying the * codec profile of the encoded output stream. * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying * whether to use a hardware accelerated or a software implementation. * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon * completion. * * @return An int32_t containing an error code from <code>pp_errors.h</code>. * Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the * requested codec profile is not supported. */ public static int Initialize(PPResource video_encoder, PPVideoFrameFormat input_format, PPSize input_visible_size, PPVideoProfile output_profile, uint initial_bitrate, PPHardwareAcceleration acceleration, PPCompletionCallback callback) { return(_Initialize(video_encoder, input_format, input_visible_size, output_profile, initial_bitrate, acceleration, callback)); }
/** * Gets the size of the video frame. * * @param[in] frame A <code>PP_Resource</code> corresponding to a video frame * resource. * @param[out] size A <code>PP_Size</code>. * * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> on success or * <code>PP_FALSE</code> on failure. */ public static PPBool GetSize(PPResource frame, out PPSize size) { return(_GetSize(frame, out size)); }
extern static PPBool _GetSize(PPResource frame, out PPSize size);
public PPRect(PPSize size) : this(size.Width, size.Height) { }
/** * GetScreenSize() gets the size of the screen in pixels. The module instance * will be resized to this size when SetFullscreen() is called to enter * fullscreen mode. * * @param[in] instance A <code>PP_Instance</code> identifying one instance * of a module. * @param[out] size The size of the entire screen in pixels. * * @return <code>PP_TRUE</code> on success or <code>PP_FALSE</code> on * failure. */ public static PPBool GetScreenSize(PPInstance instance, out PPSize size) { return(_GetScreenSize(instance, out size)); }
/** * Gets the coded size of the video frames required by the encoder. Coded * size is the logical size of the input frames, in pixels. The encoder may * have hardware alignment requirements that make this different from * |input_visible_size|, as requested in the call to Initialize(). * * @param[in] video_encoder A <code>PP_Resource</code> identifying the video * encoder. * @param[in] coded_size A <code>PP_Size</code> to hold the coded size. * @return An int32_t containing a result code from <code>pp_errors.h</code>. * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. */ public static int GetFrameCodedSize(PPResource video_encoder, out PPSize coded_size) { return(_GetFrameCodedSize(video_encoder, out coded_size)); }
extern static int _GetFrameCodedSize(PPResource video_encoder, out PPSize coded_size);
extern static PPBool _GetScreenSize(PPInstance instance, out PPSize size);
/// <summary> /// Gets the coded size of the video frames required by the encoder. Coded /// size is the logical size of the input frames, in pixels. The encoder may /// have hardware alignment requirements that make this different from /// |inputVisibleSize|, as requested in the call to Initialize(). /// </summary> /// <param name="codedSize"></param> /// <returns>Returns Failed if Initialize has not been called</returns> public PPError GetFrameCodedSize(out PPSize codedSize) { return((PPError)PPBVideoEncoder.GetFrameCodedSize(this, out codedSize)); }
extern static PPResource _Create(PPInstance instance, PPImageDataFormat format, PPSize size, PPBool init_to_zero);
extern static PPResource _Create(PPInstance instance, PPSize size, PPBool is_always_opaque);
public PPRect(PPPoint origin, PPSize size) : this(origin.X, origin.Y, size.Width, size.Height) { }
/** * Create() creates a 2D graphics context. The returned graphics context will * not be bound to the module instance on creation (call BindGraphics() on * the module instance to bind the returned graphics context to the module * instance). * * @param[in] instance The module instance. * @param[in] size The size of the graphic context. * @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag to * <code>PP_TRUE</code> if you know that you will be painting only opaque * data to this context. This option will disable blending when compositing * the module with the web page, which might give higher performance on some * computers. * * If you set <code>is_always_opaque</code>, your alpha channel should always * be set to 0xFF or there may be painting artifacts. The alpha values * overwrite the destination alpha values without blending when * <code>is_always_opaque</code> is true. * * @return A <code>PP_Resource</code> containing the 2D graphics context if * successful or 0 if unsuccessful. */ public static PPResource Create(PPInstance instance, PPSize size, PPBool is_always_opaque) { return(_Create(instance, size, is_always_opaque)); }
public PPSize(PPSize other) { width = other.Width; height = other.Height; }
extern static PPBool _Describe(PPResource graphics_2d, out PPSize size, out PPBool is_always_opaque);
/// <summary> /// Gets the size of the video frame. /// </summary> /// <param name="size">A size</param> /// <returns>True on success or false on failure.</returns> public bool GetSize(out PPSize size) => PPBVideoFrame.GetSize(this, out size) == PPBool.True;
/** * Describe() retrieves the configuration for the given graphics context, * filling the given values (which must not be <code>NULL</code>). * * @param[in] resource The 2D Graphics resource. * @param[in,out] size The size of the 2D graphics context in the browser. * @param[in,out] is_always_opaque Identifies whether only opaque data * will be painted. * * @return Returns <code>PP_TRUE</code> on success or <code>PP_FALSE</code> if * the resource is invalid. The output parameters will be set to 0 on a * <code>PP_FALSE</code>. */ public static PPBool Describe(PPResource graphics_2d, out PPSize size, out PPBool is_always_opaque) { return(_Describe(graphics_2d, out size, out is_always_opaque)); }