• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { paramMock } from "../utils"
17
18export function mockMultimediaMedia() {
19  const audioPlayerMock = {
20    play: function () {
21      console.warn("AudioPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" +
22        " may be different from that on a real device.")
23    },
24    pause: function () {
25      console.warn("AudioPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" +
26        " may be different from that on a real device.")
27    },
28    stop: function () {
29      console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" +
30        " may be different from that on a real device.")
31    },
32    reset: function () {
33      console.warn("AudioPlayer.reset interface mocked in the Previewer. How this interface works on the Previewer" +
34        " may be different from that on a real device.")
35    },
36    seek: function (...args) {
37      console.warn("AudioPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" +
38        " may be different from that on a real device.")
39    },
40    setVolume: function (...args) {
41      console.warn("AudioPlayer.setVolume interface mocked in the Previewer. How this interface works on the" +
42        " Previewer may be different from that on a real device.")
43    },
44    release: function () {
45      console.warn("AudioPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" +
46        " may be different from that on a real device.")
47    },
48    getTrackDescription: function(...args) {
49      console.warn("AudioPlayer.getTrackDescription interface mocked in the Previewer. How this interface works on the" +
50      " Previewer may be different from that on a real device.")
51      const len = args.length;
52      if (typeof args[len - 1] === 'function') {
53          args[len - 1].call(this, paramMock.businessErrorMock, [mediaDescriptionMock]);
54      } else {
55        return new Promise((resolve) => {
56          resolve([mediaDescriptionMock]);
57        });
58      }
59    },
60    src: '[PC Preview] unknow src',
61    fdSrc: AVFileDescriptor,
62    loop: '[PC Preview] unknow loop',
63    audioInterruptMode: InterruptMode,
64    currentTime: '[PC Preview] unknow currentTime',
65    duration: '[PC Preview] unknow duration',
66    state: '[PC Preview] unknow state',
67    on: function (...args) {
68      console.warn("AudioPlayer.on interface mocked in the Previewer. How this interface works on the Previewer may" +
69        " be different from that on a real device.")
70    }
71  }
72  const locationMock = {
73    latitude: '[PC Preview] unknow latitude',
74    longitude: '[PC Preview] unknow longitude',
75  }
76  const audioRecorderConfigMock = {
77    audioEncoder: '[PC Preview] unknow audioEncoder',
78    audioEncodeBitRate: '[PC Preview] unknow audioEncodeBitRate',
79    audioSampleRate: '[PC Preview] unknow audioSampleRate',
80    numberOfChannels: '[PC Preview] unknow numberOfChannels',
81    format: '[PC Preview] unknow format',
82    uri: '[PC Preview] unknow uri',
83    location: locationMock,
84    audioEncoderMime: '[PC Preview] unknow audioEncoderMime',
85    fileFormat: '[PC Preview] unknow fileFormat',
86  }
87  const audioRecorderMock = {
88    prepare: function (...args) {
89      console.warn("AudioRecorder.prepare interface mocked in the Previewer. How this interface works on the" +
90        " Previewer may be different from that on a real device.")
91    },
92    start: function () {
93      console.warn("AudioRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" +
94        " may be different from that on a real device.")
95    },
96    pause: function () {
97      console.warn("AudioRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" +
98        " may be different from that on a real device.")
99    },
100    resume: function () {
101      console.warn("AudioRecorder.resume interface mocked in the Previewer. How this interface works on the" +
102        " Previewer may be different from that on a real device.")
103    },
104    stop: function () {
105      console.warn("AudioRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" +
106        " may be different from that on a real device.")
107    },
108    release: function () {
109      console.warn("AudioRecorder.release interface mocked in the Previewer. How this interface works on the" +
110        " Previewer may be different from that on a real device.")
111    },
112    reset: function () {
113      console.warn("AudioRecorder.reset interface mocked in the Previewer. How this interface works on the Previewer" +
114        " may be different from that on a real device.")
115    },
116    on: function (...args) {
117      console.warn("AudioRecorder.on interface mocked in the Previewer. How this interface works on the Previewer" +
118        " may be different from that on a real device.")
119    }
120  }
121  const videoRecorderMock = {
122    prepare: function (...args) {
123      console.warn("VideoRecorder.prepare interface mocked in the Previewer. How this interface works on the Previewer" +
124        " may be different from that on a real device.")
125      const len = args.length;
126      if (typeof args[len - 1] === 'function') {
127          args[len - 1].call(this, paramMock.businessErrorMock);
128      } else {
129        return new Promise((resolve) => {
130          resolve();
131        });
132      }
133    },
134    getInputSurface: function (...args) {
135      console.warn("VideoRecorder.getInputSurface interface mocked in the Previewer. How this interface works on the Previewer" +
136        " may be different from that on a real device.")
137      const len = args.length;
138      if (typeof args[len - 1] === 'function') {
139          args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
140      } else {
141        return new Promise((resolve) => {
142          resolve(paramMock.paramStringMock);
143        });
144      }
145    },
146    start: function (...args) {
147      console.warn("VideoRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" +
148        " may be different from that on a real device.")
149      const len = args.length;
150      if (typeof args[len - 1] === 'function') {
151          args[len - 1].call(this, paramMock.businessErrorMock);
152      } else {
153        return new Promise((resolve) => {
154          resolve();
155        });
156      }
157    },
158    pause: function (...args) {
159      console.warn("VideoRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" +
160        " may be different from that on a real device.")
161      const len = args.length;
162      if (typeof args[len - 1] === 'function') {
163          args[len - 1].call(this, paramMock.businessErrorMock);
164      } else {
165        return new Promise((resolve) => {
166          resolve();
167        });
168      }
169    },
170    resume: function (...args) {
171      console.warn("VideoRecorder.resume interface mocked in the Previewer. How this interface works on the Previewer" +
172        " may be different from that on a real device.")
173      const len = args.length;
174      if (typeof args[len - 1] === 'function') {
175          args[len - 1].call(this, paramMock.businessErrorMock);
176      } else {
177        return new Promise((resolve) => {
178          resolve();
179        });
180      }
181    },
182    stop: function (...args) {
183      console.warn("VideoRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" +
184        " may be different from that on a real device.")
185      const len = args.length;
186      if (typeof args[len - 1] === 'function') {
187          args[len - 1].call(this, paramMock.businessErrorMock);
188      } else {
189        return new Promise((resolve) => {
190          resolve();
191        });
192      }
193    },
194    release: function (...args) {
195      console.warn("VideoRecorder.release interface mocked in the Previewer. How this interface works on the Previewer" +
196        " may be different from that on a real device.")
197      const len = args.length;
198      if (typeof args[len - 1] === 'function') {
199          args[len - 1].call(this, paramMock.businessErrorMock);
200      } else {
201        return new Promise((resolve) => {
202          resolve();
203        });
204      }
205    },
206    reset: function (...args) {
207      console.warn("VideoRecorder.reset interface mocked in the Previewer. How this interface works on the Previewer" +
208        " may be different from that on a real device.")
209      const len = args.length;
210      if (typeof args[len - 1] === 'function') {
211          args[len - 1].call(this, paramMock.businessErrorMock);
212      } else {
213        return new Promise((resolve) => {
214          resolve();
215        });
216      }
217    },
218    on: function (...args) {
219      console.warn("AudioRecorder.on interface mocked in the Previewer. How this interface works on the Previewer" +
220        " may be different from that on a real device.")
221    },
222    state: paramMock.paramStringMock,
223  }
224  const videoPlayerMock = {
225    url: '[PC Preview] unknow url',
226    fdSrc: AVFileDescriptor,
227    loop: '[PC Preview] unknow loop',
228    currentTime: '[PC Preview] unknow currentTime',
229    duration: '[PC Preview] unknow duration',
230    state: '[PC Preview] unknow state',
231    width: '[PC Preview] unknow width',
232    height: '[PC Preview] unknow height',
233    audioInterruptMode: InterruptMode,
234    videoScaleType: mediaMock.VideoScaleType,
235    setDisplaySurface: function (...args) {
236      console.warn("VideoPlayer.setDisplaySurface interface mocked in the Previewer. How this interface works on the Previewer" +
237        " may be different from that on a real device.")
238      const len = args.length;
239      if (typeof args[len - 1] === 'function') {
240          args[len - 1].call(this, paramMock.businessErrorMock);
241      } else {
242        return new Promise((resolve) => {
243          resolve();
244        });
245      }
246    },
247    prepare: function (...args) {
248      console.warn("VideoPlayer.prepare interface mocked in the Previewer. How this interface works on the Previewer" +
249        " may be different from that on a real device.")
250      const len = args.length;
251      if (typeof args[len - 1] === 'function') {
252          args[len - 1].call(this, paramMock.businessErrorMock);
253      } else {
254        return new Promise((resolve) => {
255          resolve();
256        });
257      }
258    },
259    play: function (...args) {
260      console.warn("VideoPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" +
261        " may be different from that on a real device.")
262      const len = args.length;
263      if (typeof args[len - 1] === 'function') {
264          args[len - 1].call(this, paramMock.businessErrorMock);
265      } else {
266        return new Promise((resolve) => {
267          resolve();
268        });
269      }
270    },
271    pause: function (...args) {
272      console.warn("VideoPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" +
273        " may be different from that on a real device.")
274      const len = args.length;
275      if (typeof args[len - 1] === 'function') {
276          args[len - 1].call(this, paramMock.businessErrorMock);
277      } else {
278        return new Promise((resolve) => {
279          resolve();
280        });
281      }
282    },
283    stop: function (...args) {
284      console.warn("VideoPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" +
285        " may be different from that on a real device.")
286      const len = args.length;
287      if (typeof args[len - 1] === 'function') {
288          args[len - 1].call(this, paramMock.businessErrorMock);
289      } else {
290        return new Promise((resolve) => {
291          resolve();
292        });
293      }
294    },
295    reset: function (...args) {
296      console.warn("VideoPlayer.reset interface mocked in the Previewer. How this interface works on the Previewer" +
297        " may be different from that on a real device.")
298      const len = args.length;
299      if (typeof args[len - 1] === 'function') {
300          args[len - 1].call(this, paramMock.businessErrorMock);
301      } else {
302        return new Promise((resolve) => {
303          resolve();
304        });
305      }
306    },
307    seek: function (...args) {
308      console.warn("VideoPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" +
309        " may be different from that on a real device.")
310      const len = args.length;
311      if (typeof args[len - 1] === 'function') {
312          args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
313      } else {
314        return new Promise((resolve) => {
315          resolve(paramMock.paramNumberMock);
316        });
317      }
318    },
319    setVolume: function (...args) {
320      console.warn("VideoPlayer.setVolume interface mocked in the Previewer. How this interface works on the Previewer" +
321        " may be different from that on a real device.")
322      const len = args.length;
323      if (typeof args[len - 1] === 'function') {
324          args[len - 1].call(this, paramMock.businessErrorMock);
325      } else {
326        return new Promise((resolve) => {
327          resolve();
328        });
329      }
330    },
331    release: function (...args) {
332      console.warn("VideoPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" +
333        " may be different from that on a real device.")
334      const len = args.length;
335      if (typeof args[len - 1] === 'function') {
336          args[len - 1].call(this, paramMock.businessErrorMock);
337      } else {
338        return new Promise((resolve) => {
339          resolve();
340        });
341      }
342    },
343    getTrackDescription: function (...args) {
344      console.warn("VideoPlayer.getTrackDescription interface mocked in the Previewer. How this interface works on the Previewer" +
345        " may be different from that on a real device.")
346        const len = args.length;
347        if (typeof args[len - 1] === 'function') {
348            args[len - 1].call(this, paramMock.businessErrorMock, [mediaDescriptionMock]);
349        } else {
350          return new Promise((resolve) => {
351            resolve([mediaDescriptionMock]);
352          });
353        }
354      },
355    setSpeed: function (...args) {
356      console.warn("VideoPlayer.setSpeed interface mocked in the Previewer. How this interface works on the Previewer" +
357        " may be different from that on a real device.")
358      const len = args.length;
359      if (typeof args[len - 1] === 'function') {
360          args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock);
361      } else {
362        return new Promise((resolve) => {
363          resolve();
364        });
365      }
366    },
367    selectBitrate: function (...args) {
368      console.warn("VideoPlayer.selectBitrate interface mocked in the Previewer. How this interface works on the Previewer" +
369        " may be different from that on a real device.")
370      const len = args.length;
371      if (typeof args[len - 1] === 'function') {
372          args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock);
373      } else {
374        return new Promise((resolve) => {
375          resolve(paramMock.paramNumberMock);
376        });
377      }
378    },
379    on: function (...args) {
380      console.warn("VideoPlayer.on interface mocked in the Previewer. How this interface works on the Previewer" +
381        " may be different from that on a real device.")
382    },
383  }
384  const AVFileDescriptorMock = {
385    fd: '[PC Preview] unknow fd',
386    offset: '[PC Preview] unknow audioChannels',
387    length: '[PC Preview] unknow audioCodec',
388  }
389  const videoRecorderProfileMock = {
390    audioBitrate: '[PC Preview] unknow audioBitrate',
391    audioChannels: '[PC Preview] unknow audioChannels',
392    audioCodec: '[PC Preview] unknow audioCodec',
393    audioSampleRate: '[PC Preview] unknow audioSampleRate',
394    fileFormat: '[PC Preview] unknow fileFormat',
395    videoBitrate: '[PC Preview] unknow videoBitrate',
396    videoCodec: '[PC Preview] unknow videoCodec',
397    videoFrameWidth: '[PC Preview] unknow videoFrameWidth',
398    videoFrameHeight: '[PC Preview] unknow videoFrameHeight',
399    videoFrameRate: '[PC Preview] unknow videoFrameRate',
400  }
401  const videoRecorderConfigMock = {
402    audioSourceType: '[PC Preview] unknow audioSourceType',
403    videoSourceType: '[PC Preview] unknow videoSourceType',
404    profile: '[PC Preview] unknow profile',
405    url: '[PC Preview] unknow url',
406    rotation: '[PC Preview] unknow rotation',
407    location: locationMock,
408  }
409  const mediaDescriptionMock = {
410    "key": 'paramMock.paramObjectMock',
411  }
412  const InterruptModeMock = {
413    SHARE_MODE: 0,
414    INDEPENDENT_MODE: 1
415  }
416  const mediaMock = {
417    MediaErrorCode : {
418      MSERR_OK: 0,
419      MSERR_NO_MEMORY: 1,
420      MSERR_OPERATION_NOT_PERMIT: 2,
421      MSERR_INVALID_VAL: 3,
422      MSERR_IO: 4,
423      MSERR_TIMEOUT: 5,
424      MSERR_UNKNOWN: 6,
425      MSERR_SERVICE_DIED: 7,
426      MSERR_INVALID_STATE: 8,
427      MSERR_UNSUPPORTED: 9
428    },
429    BufferingInfoType : {
430      BUFFERING_START: 1,
431      BUFFERING_END: 2,
432      BUFFERING_PERCENT: 3,
433      CACHED_DURATION: 4
434    },
435    AudioEncoder : {
436      DEFAULT: 0,
437      AMR_NB: 1,
438      AMR_WB: 2,
439      AAC_LC: 3,
440      HE_AAC: 4
441    },
442    AudioOutputFormat : {
443      DEFAULT: 0,
444      MPEG_4: 2,
445      AMR_NB: 3,
446      AMR_WB: 4,
447      AAC_ADTS: 6
448    },
449    CodecMimeType : {
450      VIDEO_H263: 'video/h263',
451      VIDEO_AVC: 'video/avc',
452      VIDEO_MPEG2: 'video/mpeg2',
453      VIDEO_MPEG4: 'video/mp4v-es',
454      VIDEO_VP8: 'video/x-vnd.on2.vp8',
455      AUDIO_AAC: 'audio/mp4a-latm',
456      AUDIO_VORBIS: 'audio/vorbis',
457      AUDIO_FLAC: 'audio/flac',
458    },
459    PlaybackSpeed : {
460      SPEED_FORWARD_0_75_X: 0,
461      SPEED_FORWARD_1_00_X: 1,
462      SPEED_FORWARD_1_25_X: 2,
463      SPEED_FORWARD_1_75_X: 3,
464      SPEED_FORWARD_2_00_X: 4,
465    },
466    VideoScaleType : {
467      VIDEO_SCALE_TYPE_FIT: 0,
468      VIDEO_SCALE_TYPE_FIT_CROP: 1,
469    },
470    ContainerFormatType : {
471      CFT_MPEG_4: "mp4",
472      CFT_MPEG_4A: "m4a",
473    },
474    MediaType : {
475      MEDIA_TYPE_AUD: 0,
476      MEDIA_TYPE_VID: 1,
477    },
478    MediaDescriptionKey : {
479      MD_KEY_TRACK_INDEX: "track_index",
480      MD_KEY_TRACK_TYPE: "track_type",
481      MD_KEY_CODEC_MIME: "codec_mime",
482      MD_KEY_DURATION: "duration",
483      MD_KEY_BITRATE: "bitrate",
484      MD_KEY_WIDTH: "width",
485      MD_KEY_HEIGHT: "height",
486      MD_KEY_FRAME_RATE: "frame_rate",
487      MD_KEY_AUD_CHANNEL_COUNT: "channel_count",
488      MD_KEY_AUD_SAMPLE_RATE: "sample_rate",
489    },
490    AudioSourceType : {
491      AUDIO_SOURCE_TYPE_DEFAULT: 0,
492      AUDIO_SOURCE_TYPE_MIC: 1,
493    },
494    VideoSourceType : {
495      VIDEO_SOURCE_TYPE_SURFACE_YUV: 0,
496      VIDEO_SOURCE_TYPE_SURFACE_ES: 1,
497    },
498    SeekMode : {
499      SEEK_NEXT_SYNC: 0,
500      SEEK_PREV_SYNC: 1,
501    },
502    AudioState: '[PC Preview] unknow AudioState',
503    VideoRecordState: '[PC Preview] unknow VideoRecordState',
504    VideoPlayState: '[PC Preview] unknow VideoPlayState',
505    createAudioPlayer: function () {
506      console.warn("media.createAudioPlayer interface mocked in the Previewer. How this interface works" +
507        " on the Previewer may be different from that on a real device.")
508      return audioPlayerMock;
509    },
510    createAudioRecorder: function () {
511      console.warn("media.createAudioRecorder interface mocked in the Previewer. How this interface works" +
512        " on the Previewer may be different from that on a real device.")
513      return audioRecorderMock;
514    },
515    createVideoPlayer: function () {
516      console.warn("media.createVideoPlayer interface mocked in the Previewer. How this interface works" +
517        " on the Previewer may be different from that on a real device.")
518      const len = args.length;
519      if (typeof args[len - 1] === 'function') {
520          args[len - 1].call(this, paramMock.businessErrorMock, videoPlayerMock);
521      } else {
522        return new Promise((resolve) => {
523          resolve(videoPlayerMock);
524        });
525      }
526    },
527    createVideoRecorder: function () {
528      console.warn("media.createVideoRecorder interface mocked in the Previewer. How this interface works" +
529        " on the Previewer may be different from that on a real device.")
530      const len = args.length;
531      if (typeof args[len - 1] === 'function') {
532          args[len - 1].call(this, paramMock.businessErrorMock, videoRecorderMock);
533      } else {
534        return new Promise((resolve) => {
535          resolve(videoRecorderMock);
536        });
537      }
538    },
539  }
540  return mediaMock;
541}
542