JpegImagesToMovie.java - Как процессор использует чтение (Buffer buf) - PullRequest
0 голосов
/ 09 ноября 2018

Я смотрю на источник кода JMF, записанный в ответ на эту ветку пользователем Mavie.Когда я пытаюсь отследить код из функции doIt -> ImageDataSource -> ImageSourceStream, мне не очень понятно, как программа считывает список файлов изображений из вектора.

Насколько яЗнаете, эта часть прочитанного кода (Buffer buf) читает файл данных изображения, но, похоже, эта функция не вызывается процессором из самого кода.

Мне удалось заставить код работать отлично, но я не понимаю логического потока.Как / Где процессор вызывает эту функцию для чтения и генерации видео?

read (Buffer buf) - часть всего исходного кода

/**
 * This is called from the Processor to read a frame worth of video
 * data.
 */
 public void read(Buffer buf) throws IOException {

        // Check if we've finished all the frames.
        if (nextImage >= images.size()) {
            // We are done. Set EndOfMedia.
            //System.err.println("Done reading all images.");
            buf.setEOM(true);
            buf.setOffset(0);
            buf.setLength(0);
            ended = true;
            return;
        }

        String imageFile = (String) images.elementAt(nextImage);
        nextImage++;

        //System.err.println("  - reading image file: " + imageFile);

        // Open a random access file for the next image.
        RandomAccessFile raFile;
        raFile = new RandomAccessFile(imageFile, "r");

        byte data[] = null;

        // Check the input buffer type & size.

        if (buf.getData() instanceof byte[])
            data = (byte[]) buf.getData();

        // Check to see the given buffer is big enough for the frame.
        if (data == null || data.length < raFile.length()) {
            data = new byte[(int) raFile.length()];
            buf.setData(data);
        }

        // Read the entire JPEG image from the file.
        raFile.readFully(data, 0, (int) raFile.length());

        //System.err.println("    read " + raFile.length() + " bytes.");

        buf.setOffset(0);
        buf.setLength((int) raFile.length());
        buf.setFormat(format);
        buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);

        // Close the random access file.
        raFile.close();
    }
...