1 /*
2  * This file is part of libbluray
3  * Copyright (C) 2010-2015 VideoLAN
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
20 package org.bluray.ti;
21 
22 import java.util.Date;
23 
24 import javax.tv.locator.Locator;
25 import javax.tv.service.ServiceInformationType;
26 import javax.tv.service.navigation.ServiceComponent;
27 import javax.tv.service.navigation.StreamType;
28 
29 import org.bluray.net.BDLocator;
30 import org.davic.net.InvalidLocatorException;
31 import org.videolan.Libbluray;
32 import org.videolan.StreamInfo;
33 import org.videolan.TIClip;
34 
35 public class PlayItemImpl implements PlayItem {
PlayItemImpl(int playlistId, int playitemId, TIClip clip, Title service)36     protected PlayItemImpl(int playlistId, int playitemId, TIClip clip, Title service) {
37         this.playlistId = playlistId;
38         this.playitemId = playitemId;
39         this.clip = clip;
40         this.service = service;
41     }
42 
getPlayItemId()43     public int getPlayItemId() {
44         return playitemId;
45     }
46 
getPlayListId()47     public int getPlayListId() {
48         return playlistId;
49     }
50 
getLocator()51     public Locator getLocator() {
52         int title = Libbluray.getCurrentTitle();
53         try {
54             return new BDLocator("bd://" + Integer.toHexString(title) + ".PLAYLIST:" + playlistId + ".ITEM:" + playitemId);
55         } catch (InvalidLocatorException e) {
56             return null;
57         }
58     }
59 
getServiceInformationType()60     public ServiceInformationType getServiceInformationType() {
61         return TitleInformationType.BD_ROM;
62     }
63 
getUpdateTime()64     public Date getUpdateTime() {
65         return null;
66     }
67 
getComponents()68     public ServiceComponent[] getComponents() {
69         StreamInfo[] video = clip.getVideoStreams();
70         StreamInfo[] audio = clip.getVideoStreams();
71         StreamInfo[] pg = clip.getVideoStreams();
72         StreamInfo[] ig = clip.getVideoStreams();
73         StreamInfo[] secVideo = clip.getVideoStreams();
74         StreamInfo[] secAudio = clip.getVideoStreams();
75 
76         int count = video.length + audio.length + pg.length + ig.length + secVideo.length + secAudio.length;
77 
78         ServiceComponent[] components = new ServiceComponent[count];
79 
80         int i = 0;
81         for (int j = 0; j < video.length; i++, j++)
82             components[i] = new TitleComponentImpl(j + 1, video[j], StreamType.VIDEO, true, playlistId, playitemId, service);
83         for (int j = 0; j < audio.length; i++, j++)
84             components[i] = new TitleComponentImpl(j + 1, audio[j], StreamType.AUDIO, true, playlistId, playitemId, service);
85         for (int j = 0; j < pg.length; i++, j++)
86             components[i] = new TitleComponentImpl(j + 1, pg[j], StreamType.SUBTITLES, true, playlistId, playitemId, service);
87         for (int j = 0; j < ig.length; i++, j++)
88             components[i] = new TitleComponentImpl(j + 1, ig[j], StreamType.DATA, true, playlistId, playitemId, service);
89         for (int j = 0; j < secVideo.length; i++, j++)
90             components[i] = new TitleComponentImpl(j + 1, secVideo[j], StreamType.VIDEO, false, playlistId, playitemId, service);
91         for (int j = 0; j < secAudio.length; i++, j++)
92             components[i] = new TitleComponentImpl(j + 1, secAudio[j], StreamType.AUDIO, false, playlistId, playitemId, service);
93 
94         return components;
95     }
96 
97     private int playlistId;
98     private int playitemId;
99     private TIClip clip;
100     private Title service;
101 }
102