File: post-processing-pipeline.vala

package info (click to toggle)
peek 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,768 kB
  • sloc: xml: 234; sh: 85; python: 69; makefile: 14
file content (72 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Peek Copyright (c) 2017 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

namespace Peek.PostProcessing {

  /**
  * Uses ffmpeg to generate PNG images for each frame.
  */
  public class PostProcessingPipeline : Object, PostProcessor {
    private Array<PostProcessor> pipeline;
    private PostProcessor? active_post_processor = null;
    private bool cancelled = false;

    public PostProcessingPipeline () {
      pipeline = new Array<PostProcessor>();
    }

    public void add (PostProcessor post_processor) {
      pipeline.append_val (post_processor);
    }

    public async Array<File>? process_async (Array<File> files) throws RecordingError {
      foreach (var post_processor in pipeline.data) {
        debug ("Running post processor %s with files %s", post_processor.get_type ().name (), files.length.to_string ());

        if (cancelled) {
          return null;
        }

        active_post_processor = post_processor;
        Array<File>? new_files = null;
        try {
          new_files = yield post_processor.process_async (files);
        } finally {
          foreach (var file in files.data) {
            try {
              yield file.delete_async ();
            } catch (Error e) {
              stderr.printf ("Error deleting temporary file %s: %s\n", file.get_path (), e.message);
            }
          }
        }

        if (new_files == null) {
          cancelled = true;
          active_post_processor = null;
          return null;
        }

        files = new_files;
      }

      active_post_processor = null;

      return files;
    }

    public void cancel () {
      if (active_post_processor != null && !cancelled) {
        cancelled = true;
        active_post_processor.cancel ();
        active_post_processor = null;
      }
    }
  }
}