View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  package org.opencastproject.composer.api;
22  
23  import java.util.Comparator;
24  
25  /*
26   * This is used to drive processEdit/processSmil after editing
27   */
28  
29  /*
30   * This structure is used to build a list of clips for concatenation, track is the src video/audio and
31   * srcId is a bit redundant, but needed for convenience.
32   * By default, it is all video
33   */
34  public class VideoClip  implements Comparable<VideoClip>, Comparator<VideoClip> {
35    private final int srcId;
36    private final long start;
37    private long end;
38  
39    /* indx is the order of the input src tracks */
40    public VideoClip(int indx, double start, double end) {
41      this.srcId = indx; // optional if only one clip, use track -> trim!
42      this.start = (long) (start * 1000);
43      this.end = (long) (end * 1000);
44    }
45  
46    public VideoClip(int indx, long start, long end) {
47      this.srcId = indx; // optional if only one clip, use track -> trim!
48      this.start = start;
49      this.end = end;
50    }
51  
52    public void setEnd(double newend) {
53      this.end = (long) (newend * 1000.0);
54    }
55  
56    public void setEnd(long newend) {
57      this.end = newend;
58    }
59  
60    public int getSrc() {
61      return srcId;
62    }
63  
64    public double getStart() {
65      return start / 1000.0;
66    }
67  
68    public double getEnd() {
69      return end / 1000.0;
70    }
71  
72    public long getStartMS() {
73      return start;
74    }
75  
76    public long getEndMS() {
77      return end;
78    }
79  
80    public double getDuration() {
81      return (end - start) / 1000.0;
82    }
83  
84    public long getDurationMS() {
85      return end - start;
86    }
87  
88  
89    @Override
90    public String toString() {
91      return "VideoClip [srcId=" + srcId + ", start=" + start + ", end=" + end + "]";
92    }
93  
94    // Order the clips by start time
95    @Override
96    public int compareTo(VideoClip other) {
97      return (int) (start - other.getStartMS());
98    }
99  
100   @Override
101   public int compare(VideoClip o1, VideoClip o2) {
102     return (int) (o1.getStartMS() - o2.getStartMS());
103   }
104 
105 }