Aizhi EdgerOS in-depth analysis of the application of Display projection module in EdgerOS

1. Display function

  • In daily application development, developers need to obtain display-related information to develop subsequent related services, such as screencasting, etc. Based on this demand, EdgerOS provides the Display module to facilitate developers to easily obtain display-related information during application development.
  • It should be noted that this module is only available in EdgerOS 1.8.0 and above, and requires display permissions to be used.

①Introduce modules:

const Display = require('display');

② Instantiation:

  • new Display(channel)
    • channel {Integer} displays device information channel identification number
    • Returns: {Object} Display object
const display = new Display(0);

③ Display list

  • Display.list()
    • Returns: {Array} A collection of legal display device information channel identification numbers
console.log(Display.list());
// [0:0]
  • Gets a valid display channel identification number.

④ Equipment information

  • display.info():Returns: {Object} Display device information
  • Obtain relevant information about the display device, which can include the following content;
    • width {Integer} horizontal pixel width
  • -high {Integer} vertical pixel width
  • -color {Integer} color depth bits
  • -linked {Boolean} Whether the monitor is connected
  • -busy {Boolean} whether it is occupied
const info = display.info();
if (info.linked) {
    
    
        console.log(info.width, 'X', info.high);
}

2. Example

  • Assuming we have similar needs for screencasting, we can use the Display module to obtain relevant information about the display device. This example is to cast advertising images to the display device. In this example, the Display module is first used to obtain the resolution information of the display device, and the ImageCodec module mentioned above is used to recode the image, and the resolution size of the advertising image is modified to be consistent with the resolution of the display device. , and finally used the previewFormat method of the MediaDecoder module to cast the modified image to the display device.
  • The sample code is as follows:
const MediaDecoder = require('mediadecoder');
const Display = require('display');
const imagecodec = require('imagecodec');
const iosched = require('iosched');

// 获取设备信息
const display = new Display(0);
const info = display.info();
const wid = info.width;
const hig = info.high;
display.close()
// 图片重新编码
const imageFile = imagecodec.decode('./test.bmp');
let newImage = imagecodec.resize(imageFile , {
    
    
  width: wid,
  height: hig,
  components: imageFile.components
});
imagecodec.encode(newImage, './temp.bmp', {
    
     quality: 80 });
// 投屏
let image = new MediaDecoder().open('file://./temp.bmp');
if (image == undefined) {
    
    
    console.error('Can not open image file!');
    return;}
image.destVideoFormat({
    
    width: 240, height: 240, fps: 1, pixelFormat: MediaDecoder.PIX_FMT_RGB24, noDrop: false, disable: false});
image.destAudioFormat({
    
    disable: true});
image.previewFormat({
    
    enable: true, fb: 0, fps: 25});
let quited = false;
 image.on('video', (video) => {
    
    
          console.log('get video frame');
          // do something
  });
 image.on('eof', () => {
    
    
          quited = true;
  });
 image.start();
 while (!quited) {
    
    
          iosched.poll(); 
          // Event poll.
 }
 image.close();
  • We can use the Display module for different business development in different scenarios. Screencasting is only part of the purpose. As long as you need to obtain information about display devices, you can consider using the Display module.

Guess you like

Origin blog.csdn.net/Forever_wj/article/details/134896557