Permalink
Browse files

Image Transcoding with im4java

  • Loading branch information...
1 parent 6ab8a9b commit 561c873c6ec195abd63e3d17f3d0fce1d7f511f7 @longkerdandy committed Jun 18, 2011
Showing with 570 additions and 2,096 deletions.
  1. +0 −5 assembly/pom.xml
  2. +7 −74 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/ContentManager.java
  3. +2 −1 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/container/VisualContainer.java
  4. +5 −0 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualPhotoItem.java
  5. +4 −0 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualPictureItem.java
  6. +3 −0 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualVideoItem.java
  7. +0 −12 mediaserver.api/src/main/java/org/chii2/mediaserver/api/http/HttpServerService.java
  8. +6 −54 mediaserver.api/src/main/java/org/chii2/mediaserver/api/http/HttpUrl.java
  9. +0 −204 mediaserver.api/src/main/java/org/chii2/mediaserver/api/provider/OnlineVideoProviderService.java
  10. +47 −0 mediaserver.api/src/main/java/org/chii2/mediaserver/api/upnp/Filter.java
  11. +44 −73 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/CommonContentManager.java
  12. +0 −1 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/MovieItem.java
  13. +2 −4 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/PhotoItem.java
  14. +2 −5 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/PictureItem.java
  15. +3 −2 ...src/main/java/org/chii2/mediaserver/content/common/container/MovieBaseStorageFolderContainer.java
  16. +3 −2 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/container/PicturesContainer.java
  17. +3 −2 ...r.core/src/main/java/org/chii2/mediaserver/content/common/container/PicturesFoldersContainer.java
  18. +3 −2 .../src/main/java/org/chii2/mediaserver/content/common/container/PicturesStorageFolderContainer.java
  19. +3 −2 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/container/RootContainer.java
  20. +3 −2 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/container/VideoContainer.java
  21. +3 −2 ...rver.core/src/main/java/org/chii2/mediaserver/content/common/container/VideoFoldersContainer.java
  22. +2 −4 mediaserver.core/src/main/java/org/chii2/mediaserver/content/wmp/WMPContentManager.java
  23. +156 −21 mediaserver.core/src/main/java/org/chii2/mediaserver/content/xbox/XBoxContentManager.java
  24. +0 −83 ...er.core/src/main/java/org/chii2/mediaserver/content/xbox/container/XBoxVideoFoldersContainer.java
  25. +14 −14 mediaserver.core/src/main/java/org/chii2/mediaserver/upnp/ContentDirectory.java
  26. +5 −17 mediaserver.core/src/main/java/org/chii2/mediaserver/upnp/MediaServerServiceImpl.java
  27. +0 −6 mediaserver.core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
  28. +1 −1 mediaserver.core/src/test/java/org/chii2/mediaserver/content/ContentManagerTest.java
  29. +0 −5 mediaserver.http/src/main/java/org/chii2/mediaserver/http/HttpServerServiceImpl.java
  30. +13 −30 mediaserver.http/src/main/java/org/chii2/mediaserver/http/bio/HttpHandler.java
  31. +108 −0 mediaserver.http/src/main/java/org/chii2/mediaserver/http/bio/entity/ImageEntity.java
  32. +0 −68 mediaserver.provider.sohu/pom.xml
  33. +0 −276 ...ovider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/OnlineVideoProviderServiceImpl.java
  34. +0 −118 ...er.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/content/container/CatalogContainer.java
  35. +0 −325 ...sohu/src/main/java/org/chii2/mediaserver/provider/sohu/content/container/CollectionContainer.java
  36. +0 −126 ...vider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/content/container/PageContainer.java
  37. +0 −51 ...vider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/content/container/RootContainer.java
  38. +0 −53 ...der.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/content/container/SeriesContainer.java
  39. +0 −57 ...provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/content/item/OnlineVideoItem.java
  40. +0 −34 mediaserver.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/Catalog.java
  41. +0 −32 ...er.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/series/SeriesGenre.java
  42. +0 −34 ...r.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/series/SeriesOrigin.java
  43. +0 −22 ...rver.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/series/SeriesPay.java
  44. +0 −23 ...ver.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/series/SeriesSort.java
  45. +0 −20 ...r.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/series/SeriesStatus.java
  46. +0 −32 ...ver.provider.sohu/src/main/java/org/chii2/mediaserver/provider/sohu/factor/series/SeriesYear.java
  47. +0 −15 mediaserver.provider.sohu/src/main/resources/OSGI-INF/blueprint/blueprint.xml
  48. +0 −6 pom.xml
  49. +26 −0 transcoder.api/src/main/java/org/chii2/transcoder/api/core/ImageTranscoderProcess.java
  50. +13 −20 transcoder.api/src/main/java/org/chii2/transcoder/api/core/TranscoderService.java
  51. +9 −150 transcoder.core/src/main/java/org/chii2/transcoder/core/TranscoderServiceImpl.java
  52. +80 −0 transcoder.core/src/main/java/org/chii2/transcoder/core/im4java/IM4JImageTranscoderProcess.java
  53. +0 −6 transcoder.core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
View
5 assembly/pom.xml
@@ -87,11 +87,6 @@
</dependency>
<dependency>
<groupId>org.chii2</groupId>
- <artifactId>chii2.mediaserver.provider.sohu</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.chii2</groupId>
<artifactId>chii2.transcoder.api</artifactId>
<scope>provided</scope>
</dependency>
View
81 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/ContentManager.java
@@ -3,15 +3,14 @@
import org.chii2.mediaserver.api.content.container.VisualContainer;
import org.chii2.mediaserver.api.content.item.VisualPictureItem;
import org.chii2.mediaserver.api.content.item.VisualVideoItem;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.api.upnp.SearchCriterion;
import org.teleal.cling.model.message.UpnpHeaders;
import org.teleal.cling.support.contentdirectory.DIDLParser;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.SortCriterion;
-import org.teleal.cling.support.model.dlna.DLNAProfiles;
-import java.net.URI;
import java.util.List;
/**
@@ -59,7 +58,7 @@
* @param orderBy Sort Method
* @return Object (Container or Item), null if not found
*/
- public DIDLObject browseObject(String objectId, String filter, long startIndex, long requestCount, SortCriterion[] orderBy);
+ public DIDLObject browseObject(String objectId, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy);
/**
* Search Object
@@ -72,7 +71,7 @@
* @param orderBy Sort Method
* @return Objects
*/
- public List<? extends DIDLObject> searchObject(String containerId, SearchCriterion searchCriteria, String filter, long startIndex, long requestCount, SortCriterion[] orderBy);
+ public List<? extends DIDLObject> searchObject(String containerId, SearchCriterion searchCriteria, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy);
/**
* Search Total Count
@@ -85,7 +84,7 @@
* @param orderBy Sort Method
* @return Total Count
*/
- public long searchCount(String containerId, SearchCriterion searchCriteria, String filter, long startIndex, long requestCount, SortCriterion[] orderBy);
+ public long searchCount(String containerId, SearchCriterion searchCriteria, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy);
/**
* Get all Pictures Storage Folder Containers in library
@@ -96,7 +95,7 @@
* @param orderBy Sort Criterion
* @return List of Pictures Storage Folder Container
*/
- public List<? extends VisualContainer> getPicturesStorageFolders(String filter, long startIndex, long maxCount, SortCriterion[] orderBy);
+ public List<? extends VisualContainer> getPicturesStorageFolders(Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy);
/**
* Get the total Pictures Storage Folder Containers count in library
@@ -116,7 +115,7 @@
* @param orderBy Sort Criterion
* @return List of Photo Item
*/
- public List<? extends VisualPictureItem> getPicturesByAlbum(String album, String parentId, String filter, long startIndex, long maxCount, SortCriterion[] orderBy);
+ public List<? extends VisualPictureItem> getPicturesByAlbum(String album, String parentId, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy);
/**
* Get total pictures count by album
@@ -136,7 +135,7 @@
* @param orderBy Sort Criterion
* @return List of Movie Item
*/
- public List<? extends VisualVideoItem> getMovies(String filter, String parentId, long startIndex, long maxCount, SortCriterion[] orderBy);
+ public List<? extends VisualVideoItem> getMovies(String parentId, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy);
/**
* Get movies count
@@ -243,70 +242,4 @@
* @return True if ID is Movie Base Storage Folder Container
*/
public boolean isMovieBaseStorageFolderContainer(String id);
-
- /**
- * ID is Online Video related Container
- *
- * @param id ID
- * @return True if ID is Online Video related Container
- */
- public boolean isOnlineVideoContainer(String id);
-
- /**
- * Forge Online Video URL
- * This likely to be a replacement for http host, and thus will use HTTP Server as proxy
- *
- * @param providerName Online Video Provider Name
- * @param url Real Online Video URL
- * @return Proxy Online Video URL
- */
- public URI forgetOnlineVideoUrl(String providerName, String url);
-
- /**
- * Get Video DLNA Profile
- *
- * @param container Container
- * @param videoFormat Video Format
- * @param videoFormatProfile Video Format Profile
- * @param videoFormatVersion Video Format Version
- * @param videoCodec Video Codec
- * @param videoBitRate BitRate
- * @param videoWidth Video Width
- * @param videoHeight Video Height
- * @param fps Video FPS
- * @param audioFormat Audio Format
- * @param audioFormatProfile Audio Format Profile
- * @param audioFormatVersion Audio Format Version
- * @param audioCodec Audio Codec
- * @param audioBitRate Audio BitRate
- * @param audioSampleBitRate Audio SampleBitRate
- * @param audioChannels Audio Channels
- * @return Video DLNA Profile
- */
- public DLNAProfiles getVideoTranscodedProfile(String container, String videoFormat, String videoFormatProfile, int videoFormatVersion, String videoCodec, long videoBitRate, int videoWidth, int videoHeight, float fps,
- String audioFormat, String audioFormatProfile, int audioFormatVersion, String audioCodec, long audioBitRate, long audioSampleBitRate, int audioChannels);
-
- /**
- * Get Video MIME
- *
- * @param container Container
- * @param videoFormat Video Format
- * @param videoFormatProfile Video Format Profile
- * @param videoFormatVersion Video Format Version
- * @param videoCodec Video Codec
- * @param videoBitRate BitRate
- * @param videoWidth Video Width
- * @param videoHeight Video Height
- * @param fps Video FPS
- * @param audioFormat Audio Format
- * @param audioFormatProfile Audio Format Profile
- * @param audioFormatVersion Audio Format Version
- * @param audioCodec Audio Codec
- * @param audioBitRate Audio BitRate
- * @param audioSampleBitRate Audio SampleBitRate
- * @param audioChannels Audio Channels
- * @return MIME
- */
- public String getVideoTranscodedMime(String container, String videoFormat, String videoFormatProfile, int videoFormatVersion, String videoCodec, long videoBitRate, int videoWidth, int videoHeight, float fps,
- String audioFormat, String audioFormatProfile, int audioFormatVersion, String audioCodec, long audioBitRate, long audioSampleBitRate, int audioChannels);
}
View
3 ...server.api/src/main/java/org/chii2/mediaserver/api/content/container/VisualContainer.java
@@ -1,6 +1,7 @@
package org.chii2.mediaserver.api.content.container;
import org.chii2.mediaserver.api.content.ContentManager;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.teleal.cling.support.model.SortCriterion;
import org.teleal.cling.support.model.container.Container;
@@ -10,7 +11,7 @@
public abstract class VisualContainer extends Container {
// Filter
- protected String filter;
+ protected Filter filter;
// Total Child Count
protected long totalChildCount;
View
5 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualPhotoItem.java
@@ -1,9 +1,14 @@
package org.chii2.mediaserver.api.content.item;
+import org.chii2.mediaserver.api.upnp.Filter;
+
/**
* Visual Photo Item
*/
public class VisualPhotoItem extends VisualPictureItem {
+ // Filter
+ protected Filter filter;
+ // Photo Class
public static final Class CLASS = new Class("object.item.imageItem.photo");
public VisualPhotoItem() {
View
4 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualPictureItem.java
@@ -1,11 +1,15 @@
package org.chii2.mediaserver.api.content.item;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.teleal.cling.support.model.item.ImageItem;
/**
* Visual Picture Item
*/
public abstract class VisualPictureItem extends ImageItem {
+ // Filter
+ protected Filter filter;
+
public String getAlbum() {
return getFirstPropertyValue(Property.UPNP.ALBUM.class);
}
View
3 mediaserver.api/src/main/java/org/chii2/mediaserver/api/content/item/VisualVideoItem.java
@@ -1,9 +1,12 @@
package org.chii2.mediaserver.api.content.item;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.teleal.cling.support.model.item.VideoItem;
/**
* Visual Video Item
*/
public abstract class VisualVideoItem extends VideoItem {
+ // Filter
+ protected Filter filter;
}
View
12 mediaserver.api/src/main/java/org/chii2/mediaserver/api/http/HttpServerService.java
@@ -32,16 +32,4 @@
* @return Movie URL
*/
public URI forgeUrl(String mediaType, String clientProfile, boolean transcoded, String mediaId);
-
- /**
- * Forge Online Media Item URL
- *
- * @param provider Provider
- * @param clientProfile Client Profile
- * @param mediaType Media Type
- * @param transcoded Transcoded or not
- * @param url Movie URL
- * @return Movie URL
- */
- public URI forgeUrl(String mediaType, String provider, String clientProfile, boolean transcoded, String url);
}
View
60 mediaserver.api/src/main/java/org/chii2/mediaserver/api/http/HttpUrl.java
@@ -40,44 +40,11 @@ public static URI forgeURL(String host, int port, String mediaType, String clien
}
/**
- * Forge URL for online media
- *
- * @param host Host Address
- * @param port Port
- * @param provider Provider Name
- * @param clientProfile Client Profile
- * @param mediaType Media Type
- * @param transcoded Transcoded or not
- * @param url Media URL
- * @return URL
- */
- public static URI forgeURL(String host, int port, String mediaType, String provider, String clientProfile, boolean transcoded, String url) {
- URI uri = null;
- String transcodedFlag;
- if (transcoded) {
- transcodedFlag = "1";
- } else {
- transcodedFlag = "0";
- }
- if (url.startsWith("/")) {
- url = url.substring(1);
- }
- try {
- uri = new URI("http://" + host + ":" + port + "/" + mediaType + "/" + provider + "/" + clientProfile + "/" + transcodedFlag + "/" + url);
- } catch (URISyntaxException ignore) {
- // This should not happens since we create the url ourselves.
- }
- return uri;
- }
-
- /**
* Parse url for media, fill result in a map like:
* "type" --- Media Type
- * "provider" --- Online Provider Name
* "client" --- Client Profile
* "transcoded" --- Transcoded (1 or 0)
* "id" --- Media ID
- * "url" --- Online Media URL
*
* @param urlTarget URL Target
* @return HashMap
@@ -109,27 +76,12 @@ public static URI forgeURL(String host, int port, String mediaType, String provi
urlTarget = urlTarget.substring(0, urlTarget.length() - 1);
}
- int typeIndex = urlTarget.indexOf("/");
- if (typeIndex > 0) {
- String type = urlTarget.substring(0, typeIndex);
- if ("onlinevideo".equalsIgnoreCase(type)) {
- String[] factors = urlTarget.split("/", 5);
- if (factors.length == 5) {
- map.put("type", factors[0] + thumb);
- map.put("provider", factors[1]);
- map.put("client", factors[2]);
- map.put("transcoded", factors[3]);
- map.put("url", factors[4]);
- }
- } else {
- String[] factors = urlTarget.split("/", 4);
- if (factors.length == 4) {
- map.put("type", factors[0] + thumb);
- map.put("client", factors[1]);
- map.put("transcoded", factors[2]);
- map.put("id", factors[3]);
- }
- }
+ String[] factors = urlTarget.split("/", 4);
+ if (factors.length == 4) {
+ map.put("type", factors[0] + thumb);
+ map.put("client", factors[1]);
+ map.put("transcoded", factors[2]);
+ map.put("id", factors[3]);
}
return map;
View
204 ...rver.api/src/main/java/org/chii2/mediaserver/api/provider/OnlineVideoProviderService.java
@@ -1,204 +0,0 @@
-package org.chii2.mediaserver.api.provider;
-
-import org.chii2.mediaserver.api.content.container.VisualContainer;
-
-import java.util.List;
-
-/**
- * Online Video Provider Service
- */
-public interface OnlineVideoProviderService {
-
- // Container Prefix
- public final static String ONLINE_VIDEO_CONTAINER_PREFIX = "OVC-";
-
- /**
- * Get the provider name
- *
- * @return Provider name
- */
- public String getProviderName();
-
- /**
- * Get Video URL Prefix
- * Basic format is: protocol://host_name:port
- * for eg: http://v.sample.com:8080
- *
- * @return Video URL Prefix
- */
- public String getVideoHostUrl();
-
- /**
- * Is given Object ID belongs to this provider
- *
- * @param id Object ID (Container or Item)
- * @return True if id belongs to this provider
- */
- public boolean isMatch(String id);
-
- /**
- * Get the Root Container
- *
- * @param filter Container Filter
- * @return Root Container
- */
- public VisualContainer getRootContainer(String filter);
-
- /**
- * Get the Container by ID
- *
- * @param filter Container Filter
- * @param id Container ID
- * @return Container
- */
- public VisualContainer getContainerByID(String filter, String id);
-
- /**
- * Get Online Video Container Format
- *
- * @param url Video URL
- * @return Container Format
- */
- public String getContainer(String url);
-
- /**
- * Get Real URL Address (List)
- * An Online Video may be cut to multiple part by service provider, so we return a List of URL here
- *
- * @param url Video URL
- * @return Real URL Address (List)
- */
- public List<String> getRealAddress(String url);
-
- /**
- * Get Online Video Pipe Commands
- * Pipe Commands are used in Transcoder as stream input
- * for eg: ffmpeg -i - will be used to read from pipe.
- * Pipe input usually be done by Wget or customer downloader.
- * Please Note: this should be the REAL URL here
- *
- * @param url Real Video URL
- * @return Pipe Commands
- */
- public List<String> getPipe(String url);
-
- /**
- * Get Online Video Format
- *
- * @param url Video URL
- * @return Video Format
- */
- public String getVideoFormat(String url);
-
- /**
- * Get Online Video Format Profile
- *
- * @param url Video URL
- * @return Video Format Profile
- */
- public String getVideoFormatProfile(String url);
-
- /**
- * Get Online Video Format Version
- *
- * @param url Video URL
- * @return Video Format Version
- */
- public int getVideoFormatVersion(String url);
-
- /**
- * Get Online Video Codec
- *
- * @param url Video URL
- * @return Video Codec
- */
- public String getVideoCodec(String url);
-
- /**
- * Get Online Video BitRate
- *
- * @param url Video URL
- * @return Video BitRate
- */
- public long getVideoBitRate(String url);
-
- /**
- * Get Online Video Width
- *
- * @param url Video URL
- * @return Video Width
- */
- public int getVideoWidth(String url);
-
- /**
- * Get Online Video Height
- *
- * @param url Video URL
- * @return Video Height
- */
- public int getVideoHeight(String url);
-
- /**
- * Get Online Video FPS
- *
- * @param url Video URL
- * @return Video FPS
- */
- public float getVideoFps(String url);
-
- /**
- * Get Online Video Audio Format
- *
- * @param url Video URL
- * @return Audio Format
- */
- public String getAudioFormat(String url);
-
- /**
- * Get Online Video Audio Format Profile
- *
- * @param url Video URL
- * @return Audio Format Profile
- */
- public String getAudioFormatProfile(String url);
-
- /**
- * Get Online Video Audio Format Version
- *
- * @param url Video URL
- * @return Audio Format Version
- */
- public int getAudioFormatVersion(String url);
-
- /**
- * Get Online Video Audio Codec
- *
- * @param url Video URL
- * @return Audio Codec
- */
- public String getAudioCodec(String url);
-
- /**
- * Get Online Video Audio BitRate
- *
- * @param url Video URL
- * @return Audio BitRate
- */
- public long getAudioBitRate(String url);
-
- /**
- * Get Online Video Audio Sample BitRate
- *
- * @param url Video URL
- * @return Audio Sample BitRate
- */
- public long getAudioSampleBitRate(String url);
-
- /**
- * Get Online Video Audio Channels
- *
- * @param url Video URL
- * @return Audio Channels
- */
- public int getAudioChannels(String url);
-}
View
47 mediaserver.api/src/main/java/org/chii2/mediaserver/api/upnp/Filter.java
@@ -0,0 +1,47 @@
+package org.chii2.mediaserver.api.upnp;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Filter
+ */
+public class Filter {
+ // Match all the filed
+ private boolean isMatchAll = false;
+ // Filed Map
+ private List<String> fieldList = new ArrayList<String>();
+
+ /**
+ * Constructor
+ *
+ * @param filter Filter String
+ */
+ public Filter(String filter) {
+ if (filter != null) {
+ filter = StringUtils.trim(filter);
+ if ("*".equalsIgnoreCase(filter)) {
+ this.isMatchAll = true;
+ } else {
+ String[] fields = filter.split(",");
+ if (fields != null) {
+ for (String field : fields) {
+ this.fieldList.add(field);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Field is contained in Filter
+ *
+ * @param field UPnP Field
+ * @return True if field in the Filter
+ */
+ public boolean contains(String field) {
+ return this.isMatchAll || this.fieldList.contains(field);
+ }
+}
View
117 ...aserver.core/src/main/java/org/chii2/mediaserver/content/common/CommonContentManager.java
@@ -8,7 +8,7 @@
import org.chii2.mediaserver.api.content.item.VisualPictureItem;
import org.chii2.mediaserver.api.content.item.VisualVideoItem;
import org.chii2.mediaserver.api.http.HttpServerService;
-import org.chii2.mediaserver.api.provider.OnlineVideoProviderService;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.api.upnp.SearchCriterion;
import org.chii2.mediaserver.content.common.Item.PhotoItem;
import org.chii2.mediaserver.content.common.Item.PictureItem;
@@ -55,8 +55,6 @@
protected HttpServerService httpServer;
// Transcoder
protected TranscoderService transcoder;
- // Online Videos
- protected List<OnlineVideoProviderService> onlineVideos;
// Logger
protected Logger logger = LoggerFactory.getLogger("org.chii2.mediaserver.content");
// UUID Length
@@ -68,13 +66,11 @@
* @param mediaLibrary Media Library
* @param httpServer Http Server
* @param transcoder Transcoder
- * @param onlineVideos Online Video Providers
*/
- public CommonContentManager(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder, List<OnlineVideoProviderService> onlineVideos) {
+ public CommonContentManager(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder) {
this.mediaLibrary = mediaLibrary;
this.httpServer = httpServer;
this.transcoder = transcoder;
- this.onlineVideos = onlineVideos;
}
@Override
@@ -99,7 +95,7 @@ public boolean isMatch(UpnpHeaders headers) {
}
@Override
- public DIDLObject browseObject(String objectId, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
+ public DIDLObject browseObject(String objectId, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
// Root Container
if (isRootContainer(objectId)) {
VisualContainer container = new RootContainer(filter);
@@ -155,7 +151,7 @@ else if (isMovieBaseStorageFolderContainer(objectId)) {
}
@Override
- public List<? extends DIDLObject> searchObject(String containerId, SearchCriterion searchCriteria, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
+ public List<? extends DIDLObject> searchObject(String containerId, SearchCriterion searchCriteria, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
List<? extends DIDLObject> results = null;
switch (searchCriteria.getSearchType()) {
case SEARCH_IMAGE:
@@ -166,7 +162,7 @@ else if (isMovieBaseStorageFolderContainer(objectId)) {
}
@Override
- public long searchCount(String containerId, SearchCriterion searchCriteria, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
+ public long searchCount(String containerId, SearchCriterion searchCriteria, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
long result = 0;
switch (searchCriteria.getSearchType()) {
case SEARCH_IMAGE:
@@ -177,7 +173,7 @@ public long searchCount(String containerId, SearchCriterion searchCriteria, Stri
}
// Search Image
- private List<? extends DIDLObject> searchImage(String containerId, SearchCriterion searchCriteria, String filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
+ private List<? extends DIDLObject> searchImage(String containerId, SearchCriterion searchCriteria, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
// Forge sort
Map<String, String> sorts = new HashMap<String, String>();
for (SortCriterion sort : orderBy) {
@@ -299,12 +295,12 @@ public long searchCount(String containerId, SearchCriterion searchCriteria, Stri
}
// Search Image Count
- public long searchImageCount(String containerId, SearchCriterion searchCriteria, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
+ public long searchImageCount(String containerId, SearchCriterion searchCriteria, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
return this.mediaLibrary.getImagesCount();
}
@Override
- public List<PicturesStorageFolderContainer> getPicturesStorageFolders(String filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
+ public List<PicturesStorageFolderContainer> getPicturesStorageFolders(Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
// Forge sort
Map<String, String> sorts = new HashMap<String, String>();
for (SortCriterion sort : orderBy) {
@@ -350,7 +346,7 @@ public long getPicturesStorageFoldersCount() {
}
@Override
- public List<VisualPictureItem> getPicturesByAlbum(String album, String parentId, String filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
+ public List<VisualPictureItem> getPicturesByAlbum(String album, String parentId, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
// Forge sort
Map<String, String> sorts = new HashMap<String, String>();
for (SortCriterion sort : orderBy) {
@@ -442,7 +438,7 @@ public long getPicturesStorageFoldersCount() {
if (originalProfile != null && originalProfile != DLNAProfiles.NONE) {
dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_PN, new DLNAProfileAttribute(originalProfile));
}
- dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP, new DLNAOperationsAttribute(DLNAOperations.RANGE));
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP, new DLNAOperationsAttribute(DLNAOperations.NONE));
dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_FLAGS, new DLNAFlagsAttribute(DLNAFlags.STREAMING_TRANSFER_MODE, DLNAFlags.BACKGROUND_TRANSFERT_MODE, DLNAFlags.DLNA_V15));
originalResource.setProtocolInfo(new DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, mime, dlnaAttributes));
// Resolution
@@ -460,7 +456,39 @@ public long getPicturesStorageFoldersCount() {
// Add Resource to item
pictureItem.addResource(originalResource);
} else {
- // TODO: Transcoded Image Handling
+ // Resource
+ Res transcodedResource = this.getResource();
+ // URL
+ URI transcodedUri = this.httpServer.forgeUrl("image", getClientProfile(), true, libraryId);
+ transcodedResource.setValue(transcodedUri.toString());
+ // Profile
+ DLNAProfiles transcodedProfile = this.transcoder.getImageTranscodedProfile(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight());
+ // MIME
+ String mime = this.transcoder.getImageTranscodedMime(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight());
+ // This should not happens
+ if (StringUtils.isBlank(mime)) {
+ mime = image.getMimeType();
+ logger.warn("Can't determine image MIME type, use {} from file information.", mime);
+ }
+ // DLNA Attribute
+ EnumMap<DLNAAttribute.Type, DLNAAttribute> dlnaAttributes = new EnumMap<DLNAAttribute.Type, DLNAAttribute>(DLNAAttribute.Type.class);
+ if (transcodedProfile != null && transcodedProfile != DLNAProfiles.NONE) {
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_PN, new DLNAProfileAttribute(transcodedProfile));
+ }
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_CI, new DLNAConversionIndicatorAttribute(DLNAConversionIndicator.TRANSCODED));
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP, new DLNAOperationsAttribute(DLNAOperations.NONE));
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_FLAGS, new DLNAFlagsAttribute(DLNAFlags.STREAMING_TRANSFER_MODE, DLNAFlags.BACKGROUND_TRANSFERT_MODE, DLNAFlags.DLNA_V15));
+ transcodedResource.setProtocolInfo(new DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, mime, dlnaAttributes));
+ // Resolution
+ if (filter.contains("res@resolution")) {
+ transcodedResource.setResolution(image.getWidth(), image.getHeight());
+ }
+ // Color Depth
+ if (filter.contains("res@colorDepth")) {
+ transcodedResource.setColorDepth((long) image.getColorDepth());
+ }
+ // Add Resource to item
+ pictureItem.addResource(transcodedResource);
}
// Add to results
pictures.add(pictureItem);
@@ -474,7 +502,7 @@ public long getPicturesCountByAlbum(String album) {
}
@Override
- public List<? extends VisualVideoItem> getMovies(String parentId, String filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
+ public List<? extends VisualVideoItem> getMovies(String parentId, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
// TODO: finished this later
return null;
}
@@ -566,61 +594,4 @@ public boolean isVideoFoldersContainer(String id) {
public boolean isMovieBaseStorageFolderContainer(String id) {
return MOVIE_BASE_STORAGE_FOLDER_ID.equalsIgnoreCase(id);
}
-
- @Override
- public boolean isOnlineVideoContainer(String id) {
- return id != null && id.length() > 4 && id.substring(0, 4).equalsIgnoreCase(OnlineVideoProviderService.ONLINE_VIDEO_CONTAINER_PREFIX);
- }
-
- @Override
- public URI forgetOnlineVideoUrl(String providerName, String url) {
- OnlineVideoProviderService onlineVideo = this.getOnlineVideoProvider(providerName);
- if (onlineVideo != null) {
- url = url.replace(onlineVideo.getVideoHostUrl(), "");
- return httpServer.forgeUrl("onlinevideo", providerName, this.getClientProfile(), true, url);
- } else {
- return null;
- }
- }
-
- @Override
- public DLNAProfiles getVideoTranscodedProfile(String container, String videoFormat, String videoFormatProfile, int videoFormatVersion, String videoCodec, long videoBitRate, int videoWidth, int videoHeight, float fps, String audioFormat, String audioFormatProfile, int audioFormatVersion, String audioCodec, long audioBitRate, long audioSampleBitRate, int audioChannels) {
- return transcoder.getVideoTranscodedProfile(getClientProfile(), container, videoFormat, videoFormatProfile, videoFormatVersion, videoCodec, videoBitRate, videoWidth, videoHeight, fps, audioFormat, audioFormatProfile, audioFormatVersion, audioCodec, audioBitRate, audioSampleBitRate, audioChannels);
- }
-
- @Override
- public String getVideoTranscodedMime(String container, String videoFormat, String videoFormatProfile, int videoFormatVersion, String videoCodec, long videoBitRate, int videoWidth, int videoHeight, float fps, String audioFormat, String audioFormatProfile, int audioFormatVersion, String audioCodec, long audioBitRate, long audioSampleBitRate, int audioChannels) {
- return transcoder.getVideoTranscodedMime(getClientProfile(), container, videoFormat, videoFormatProfile, videoFormatVersion, videoCodec, videoBitRate, videoWidth, videoHeight, fps, audioFormat, audioFormatProfile, audioFormatVersion, audioCodec, audioBitRate, audioSampleBitRate, audioChannels);
- }
-
- /**
- * Get Online Video Provider by Name
- *
- * @param providerName Provider Name
- * @return Online Video Provider
- */
- protected OnlineVideoProviderService getOnlineVideoProvider(String providerName) {
- for (OnlineVideoProviderService onlineVideo : onlineVideos) {
- if (onlineVideo.getProviderName().equalsIgnoreCase(providerName)) {
- return onlineVideo;
- }
- }
- return null;
- }
-
- /**
- * Get Online Video Container from Provider
- *
- * @param filter Filter
- * @param id Object ID
- * @return Online Video Container
- */
- protected VisualContainer getOnlineVideoContainer(String filter, String id) {
- for (OnlineVideoProviderService onlineVideo : onlineVideos) {
- if (onlineVideo.isMatch(id)) {
- return onlineVideo.getContainerByID(filter, id);
- }
- }
- return null;
- }
}
View
1 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/MovieItem.java
@@ -9,7 +9,6 @@
* Especially represent a movie
*/
public class MovieItem extends VisualVideoItem {
-
/**
* Constructor
*
View
6 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/PhotoItem.java
@@ -1,14 +1,12 @@
package org.chii2.mediaserver.content.common.Item;
import org.chii2.mediaserver.api.content.item.VisualPhotoItem;
+import org.chii2.mediaserver.api.upnp.Filter;
/**
* Photo Item
*/
public class PhotoItem extends VisualPhotoItem {
- // Filter
- private String filter;
-
/**
* Constructor
*
@@ -18,7 +16,7 @@
* @param title Item Title
* @param album Album
*/
- public PhotoItem(String filter, String id, String parentId, String title, String album) {
+ public PhotoItem(Filter filter, String id, String parentId, String title, String album) {
super();
this.filter = filter;
View
7 mediaserver.core/src/main/java/org/chii2/mediaserver/content/common/Item/PictureItem.java
@@ -1,15 +1,12 @@
package org.chii2.mediaserver.content.common.Item;
import org.chii2.mediaserver.api.content.item.VisualPictureItem;
+import org.chii2.mediaserver.api.upnp.Filter;
/**
* Picture Item
*/
public class PictureItem extends VisualPictureItem {
-
- // Filter
- private String filter;
-
/**
* Constructor
*
@@ -19,7 +16,7 @@
* @param title Item Title
* @param album Album
*/
- public PictureItem(String filter, String id, String parentId, String title, String album) {
+ public PictureItem(Filter filter, String id, String parentId, String title, String album) {
super();
this.filter = filter;
View
5 .../java/org/chii2/mediaserver/content/common/container/MovieBaseStorageFolderContainer.java
@@ -3,6 +3,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
import org.chii2.mediaserver.api.content.item.VisualVideoItem;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -22,7 +23,7 @@
*
* @param filter Content Filter
*/
- public MovieBaseStorageFolderContainer(String filter) {
+ public MovieBaseStorageFolderContainer(Filter filter) {
this(filter, CommonContentManager.MOVIE_BASE_STORAGE_FOLDER_ID, CommonContentManager.VIDEO_FOLDERS_ID);
}
@@ -33,7 +34,7 @@ public MovieBaseStorageFolderContainer(String filter) {
* @param id Container ID
* @param parentId Parent ID
*/
- public MovieBaseStorageFolderContainer(String filter, String id, String parentId) {
+ public MovieBaseStorageFolderContainer(Filter filter, String id, String parentId) {
super();
this.filter = filter;
View
5 ....core/src/main/java/org/chii2/mediaserver/content/common/container/PicturesContainer.java
@@ -2,6 +2,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -18,7 +19,7 @@
*
* @param filter Content Filter
*/
- public PicturesContainer(String filter) {
+ public PicturesContainer(Filter filter) {
this(filter, CommonContentManager.PICTURES_ID, CommonContentManager.ROOT_ID);
}
@@ -29,7 +30,7 @@ public PicturesContainer(String filter) {
* @param id Container ID
* @param parentId Parent ID
*/
- public PicturesContainer(String filter, String id, String parentId) {
+ public PicturesContainer(Filter filter, String id, String parentId) {
super();
this.filter = filter;
View
5 ...rc/main/java/org/chii2/mediaserver/content/common/container/PicturesFoldersContainer.java
@@ -2,6 +2,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -20,7 +21,7 @@
*
* @param filter Content Filter
*/
- public PicturesFoldersContainer(String filter) {
+ public PicturesFoldersContainer(Filter filter) {
this(filter, CommonContentManager.PICTURES_FOLDERS_ID, CommonContentManager.PICTURES_ID);
}
@@ -31,7 +32,7 @@ public PicturesFoldersContainer(String filter) {
* @param id Container ID
* @param parentId Parent ID
*/
- public PicturesFoldersContainer(String filter, String id, String parentId) {
+ public PicturesFoldersContainer(Filter filter, String id, String parentId) {
super();
this.filter = filter;
View
5 ...n/java/org/chii2/mediaserver/content/common/container/PicturesStorageFolderContainer.java
@@ -3,6 +3,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
import org.chii2.mediaserver.api.content.item.VisualPictureItem;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -22,7 +23,7 @@
* @param id Container ID
* @param title Container Title
*/
- public PicturesStorageFolderContainer(String filter, String id, String title) {
+ public PicturesStorageFolderContainer(Filter filter, String id, String title) {
this(filter, id, CommonContentManager.PICTURES_FOLDERS_ID, title);
}
@@ -33,7 +34,7 @@ public PicturesStorageFolderContainer(String filter, String id, String title) {
* @param parentId Container Parent ID
* @param title Container Title
*/
- public PicturesStorageFolderContainer(String filter, String id, String parentId, String title) {
+ public PicturesStorageFolderContainer(Filter filter, String id, String parentId, String title) {
super();
this.filter = filter;
View
5 ...rver.core/src/main/java/org/chii2/mediaserver/content/common/container/RootContainer.java
@@ -2,6 +2,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -17,7 +18,7 @@
*
* @param filter Content Filter
*/
- public RootContainer(String filter) {
+ public RootContainer(Filter filter) {
this(filter, CommonContentManager.ROOT_ID, "-1");
}
@@ -28,7 +29,7 @@ public RootContainer(String filter) {
* @param id Container ID
* @param parentId Parent ID
*/
- public RootContainer(String filter, String id, String parentId) {
+ public RootContainer(Filter filter, String id, String parentId) {
super();
this.filter = filter;
View
5 ...ver.core/src/main/java/org/chii2/mediaserver/content/common/container/VideoContainer.java
@@ -2,6 +2,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -18,7 +19,7 @@
*
* @param filter Content Filter
*/
- public VideoContainer(String filter) {
+ public VideoContainer(Filter filter) {
this(filter, CommonContentManager.VIDEO_ID, CommonContentManager.ROOT_ID);
}
@@ -29,7 +30,7 @@ public VideoContainer(String filter) {
* @param id Container ID
* @param parentId Parent ID
*/
- public VideoContainer(String filter, String id, String parentId) {
+ public VideoContainer(Filter filter, String id, String parentId) {
super();
this.filter = filter;
View
5 ...e/src/main/java/org/chii2/mediaserver/content/common/container/VideoFoldersContainer.java
@@ -2,6 +2,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.SortCriterion;
@@ -18,7 +19,7 @@
*
* @param filter Content Filter
*/
- public VideoFoldersContainer(String filter) {
+ public VideoFoldersContainer(Filter filter) {
this(filter, CommonContentManager.VIDEO_FOLDERS_ID, CommonContentManager.VIDEO_ID);
}
@@ -29,7 +30,7 @@ public VideoFoldersContainer(String filter) {
* @param id Container ID
* @param parentId Parent ID
*/
- public VideoFoldersContainer(String filter, String id, String parentId) {
+ public VideoFoldersContainer(Filter filter, String id, String parentId) {
super();
this.filter = filter;
View
6 mediaserver.core/src/main/java/org/chii2/mediaserver/content/wmp/WMPContentManager.java
@@ -2,7 +2,6 @@
import org.chii2.medialibrary.api.core.MediaLibraryService;
import org.chii2.mediaserver.api.http.HttpServerService;
-import org.chii2.mediaserver.api.provider.OnlineVideoProviderService;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.chii2.transcoder.api.core.TranscoderService;
import org.teleal.cling.model.message.UpnpHeaders;
@@ -19,10 +18,9 @@
* @param mediaLibrary Media Library
* @param httpServer Http Server
* @param transcoder Transcoder
- * @param onlineVideos Online Video Providers
*/
- public WMPContentManager(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder, List<OnlineVideoProviderService> onlineVideos) {
- super(mediaLibrary, httpServer, transcoder, onlineVideos);
+ public WMPContentManager(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder) {
+ super(mediaLibrary, httpServer, transcoder);
}
@Override
View
177 mediaserver.core/src/main/java/org/chii2/mediaserver/content/xbox/XBoxContentManager.java
@@ -3,16 +3,18 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.chii2.medialibrary.api.core.MediaLibraryService;
+import org.chii2.medialibrary.api.persistence.entity.Image;
import org.chii2.medialibrary.api.persistence.entity.Movie;
import org.chii2.mediaserver.api.content.container.VisualContainer;
import org.chii2.mediaserver.api.content.item.VisualPictureItem;
import org.chii2.mediaserver.api.content.item.VisualVideoItem;
import org.chii2.mediaserver.api.http.HttpServerService;
-import org.chii2.mediaserver.api.provider.OnlineVideoProviderService;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.chii2.mediaserver.content.common.Item.MovieItem;
+import org.chii2.mediaserver.content.common.Item.PhotoItem;
+import org.chii2.mediaserver.content.common.Item.PictureItem;
import org.chii2.mediaserver.content.common.container.*;
-import org.chii2.mediaserver.content.xbox.container.XBoxVideoFoldersContainer;
import org.chii2.transcoder.api.core.TranscoderService;
import org.chii2.util.EncodingUtils;
import org.teleal.cling.model.message.UpnpHeaders;
@@ -23,6 +25,7 @@
import org.teleal.cling.support.model.item.Item;
import java.net.URI;
+import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -36,10 +39,9 @@
* @param mediaLibrary Media Library
* @param httpServer Http Server
* @param transcoder Transcoder
- * @param onlineVideos Online Video Providers
*/
- public XBoxContentManager(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder, List<OnlineVideoProviderService> onlineVideos) {
- super(mediaLibrary, httpServer, transcoder, onlineVideos);
+ public XBoxContentManager(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder) {
+ super(mediaLibrary, httpServer, transcoder);
}
@Override
@@ -70,7 +72,7 @@ public boolean isMatch(UpnpHeaders headers) {
}
@Override
- public DIDLObject browseObject(String objectId, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
+ public DIDLObject browseObject(String objectId, Filter filter, long startIndex, long requestCount, SortCriterion[] orderBy) {
// Root Container
if (isRootContainer(objectId)) {
VisualContainer container = new RootContainer(filter);
@@ -111,7 +113,7 @@ else if (isVideoContainer(objectId)) {
// Video Folders Container
// For XBox360, this is the root video folder in dashboard
else if (isVideoFoldersContainer(objectId)) {
- VisualContainer container = new XBoxVideoFoldersContainer(filter, this.onlineVideos);
+ VisualContainer container = new VideoFoldersContainer(filter);
container.loadContents(startIndex, requestCount, orderBy, this);
convertVideoContainerS2T(container);
return container;
@@ -123,19 +125,6 @@ else if (isMovieBaseStorageFolderContainer(objectId)) {
convertVideoContainerS2T(container);
return container;
}
- // Online Video Container
- else if (isOnlineVideoContainer(objectId)) {
- VisualContainer container = getOnlineVideoContainer(filter, objectId);
- if (container != null) {
- container.loadContents(startIndex, requestCount, orderBy, this);
- // If container is online video provider's Root Container, set its parent to Video Folders Container
- convertVideoContainerS2T(container);
- if (container.getParentID().equalsIgnoreCase("-1")) {
- container.setParentID("15");
- }
- }
- return container;
- }
// Invalid
else {
// TODO Maybe should throw a NO_SUCH_OBJECT exception, instead of null result
@@ -144,7 +133,153 @@ else if (isOnlineVideoContainer(objectId)) {
}
@Override
- public List<? extends VisualVideoItem> getMovies(String parentId, String filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
+ public List<VisualPictureItem> getPicturesByAlbum(String album, String parentId, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
+ // Forge sort
+ Map<String, String> sorts = new HashMap<String, String>();
+ for (SortCriterion sort : orderBy) {
+ String field = null;
+ if ("dc:title".equalsIgnoreCase(sort.getPropertyName())) {
+ field = "title";
+ } else if ("dc:date".equalsIgnoreCase(sort.getPropertyName())) {
+ field = "file.date_taken";
+ }
+ if (field != null) {
+ if (sort.isAscending()) {
+ sorts.put(field, "asc");
+ } else {
+ sorts.put(field, "desc");
+ }
+ }
+ }
+ // Get images from library
+ List<? extends Image> images;
+
+ int start = -1;
+ int max = -1;
+ try {
+ start = (int) startIndex;
+ max = (int) maxCount;
+ } catch (Exception ignore) {
+ }
+ images = this.mediaLibrary.getImagesByField("album", album, true, start, max, sorts);
+
+ // Results
+ List<VisualPictureItem> pictures = new ArrayList<VisualPictureItem>();
+ // Create picture item and add to results
+ for (Image image : images) {
+ // Item
+ VisualPictureItem pictureItem;
+ // ID from library
+ String libraryId = image.getId();
+ // ID
+ String id;
+ // Title
+ String title = image.getTitle();
+ // For XBox360, it must be Photo Item
+ id = forgeItemId(libraryId, parentId, PHOTO_ITEM_PREFIX);
+ pictureItem = new PhotoItem(filter, id, parentId, title, image.getAlbum());
+
+
+ //Picture Date
+ Date date = image.getDateTaken();
+ if (filter.contains("dc:date") && date != null) {
+ pictureItem.setDate(new SimpleDateFormat("yyyy-MM-dd").format(date));
+ }
+ String comment = image.getUserComment();
+ // Description
+ if (filter.contains("dc:description") && StringUtils.isNotBlank(comment)) {
+ pictureItem.setDescription(comment);
+ }
+ // Long Description
+ if (filter.contains("upnp:longDescription") && StringUtils.isNotBlank(comment)) {
+ pictureItem.setLongDescription(comment);
+ }
+ // Rating
+ float rating = image.getRating();
+ if (filter.contains("upnp:rating") && rating > 0) {
+ pictureItem.setRating(Float.toString(rating));
+ }
+
+ // Resource
+ if (this.transcoder.isValidImage(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight())) {
+ // Resource
+ Res originalResource = this.getResource();
+ // URL
+ URI originalUri = this.httpServer.forgeUrl("image", getClientProfile(), false, libraryId);
+ originalResource.setValue(originalUri.toString());
+ // Profile
+ DLNAProfiles originalProfile = this.transcoder.getImageTranscodedProfile(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight());
+ // MIME
+ String mime = this.transcoder.getImageTranscodedMime(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight());
+ // This should not happens
+ if (StringUtils.isBlank(mime)) {
+ mime = image.getMimeType();
+ logger.warn("Can't determine image MIME type, use {} from file information.", mime);
+ }
+ // DLNA Attribute
+ EnumMap<DLNAAttribute.Type, DLNAAttribute> dlnaAttributes = new EnumMap<DLNAAttribute.Type, DLNAAttribute>(DLNAAttribute.Type.class);
+ if (originalProfile != null && originalProfile != DLNAProfiles.NONE) {
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_PN, new DLNAProfileAttribute(originalProfile));
+ }
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP, new DLNAOperationsAttribute(DLNAOperations.NONE));
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_FLAGS, new DLNAFlagsAttribute(DLNAFlags.STREAMING_TRANSFER_MODE, DLNAFlags.BACKGROUND_TRANSFERT_MODE, DLNAFlags.DLNA_V15));
+ originalResource.setProtocolInfo(new DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, mime, dlnaAttributes));
+ // Resolution
+ if (filter.contains("res@resolution")) {
+ originalResource.setResolution(image.getWidth(), image.getHeight());
+ }
+ // Color Depth
+ if (filter.contains("res@colorDepth")) {
+ originalResource.setColorDepth((long) image.getColorDepth());
+ }
+ // Size
+ if (filter.contains("res@size")) {
+ originalResource.setSize(image.getSize());
+ }
+ // Add Resource to item
+ pictureItem.addResource(originalResource);
+ } else {
+ // Resource
+ Res transcodedResource = this.getResource();
+ // URL
+ URI transcodedUri = this.httpServer.forgeUrl("image", getClientProfile(), true, libraryId);
+ transcodedResource.setValue(transcodedUri.toString());
+ // Profile
+ DLNAProfiles transcodedProfile = this.transcoder.getImageTranscodedProfile(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight());
+ // MIME
+ String mime = this.transcoder.getImageTranscodedMime(this.getClientProfile(), image.getType(), image.getWidth(), image.getHeight());
+ // This should not happens
+ if (StringUtils.isBlank(mime)) {
+ mime = image.getMimeType();
+ logger.warn("Can't determine image MIME type, use {} from file information.", mime);
+ }
+ // DLNA Attribute
+ EnumMap<DLNAAttribute.Type, DLNAAttribute> dlnaAttributes = new EnumMap<DLNAAttribute.Type, DLNAAttribute>(DLNAAttribute.Type.class);
+ if (transcodedProfile != null && transcodedProfile != DLNAProfiles.NONE) {
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_PN, new DLNAProfileAttribute(transcodedProfile));
+ }
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP, new DLNAOperationsAttribute(DLNAOperations.NONE));
+ dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_FLAGS, new DLNAFlagsAttribute(DLNAFlags.STREAMING_TRANSFER_MODE, DLNAFlags.BACKGROUND_TRANSFERT_MODE, DLNAFlags.DLNA_V15));
+ transcodedResource.setProtocolInfo(new DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, mime, dlnaAttributes));
+ // Resolution
+ if (filter.contains("res@resolution")) {
+ transcodedResource.setResolution(image.getWidth(), image.getHeight());
+ }
+ // Color Depth
+ if (filter.contains("res@colorDepth")) {
+ transcodedResource.setColorDepth((long) image.getColorDepth());
+ }
+ // Add Resource to item
+ pictureItem.addResource(transcodedResource);
+ }
+ // Add to results
+ pictures.add(pictureItem);
+ }
+ return pictures;
+ }
+
+ @Override
+ public List<? extends VisualVideoItem> getMovies(String parentId, Filter filter, long startIndex, long maxCount, SortCriterion[] orderBy) {
// Forge sort TODO: May need more filed in the future
Map<String, String> sorts = new HashMap<String, String>();
for (SortCriterion sort : orderBy) {
View
83 ...src/main/java/org/chii2/mediaserver/content/xbox/container/XBoxVideoFoldersContainer.java
@@ -1,83 +0,0 @@
-package org.chii2.mediaserver.content.xbox.container;
-
-import org.chii2.mediaserver.api.content.ContentManager;
-import org.chii2.mediaserver.api.content.container.VisualContainer;
-import org.chii2.mediaserver.api.provider.OnlineVideoProviderService;
-import org.chii2.mediaserver.content.common.container.MovieBaseStorageFolderContainer;
-import org.chii2.mediaserver.content.common.container.VideoFoldersContainer;
-import org.teleal.cling.support.model.SortCriterion;
-
-import java.util.List;
-
-/**
- * XBox Video Folders Container.
- */
-public class XBoxVideoFoldersContainer extends VideoFoldersContainer {
-
- // Online Videos
- private List<OnlineVideoProviderService> onlineVideos;
-
- /**
- * Constructor
- *
- * @param filter Content Filter
- */
- public XBoxVideoFoldersContainer(String filter) {
- super(filter);
- }
-
- /**
- * Constructor
- *
- * @param filter Content Filter
- * @param onlineVideos Online Video Providers
- */
- public XBoxVideoFoldersContainer(String filter, List<OnlineVideoProviderService> onlineVideos) {
- super(filter);
- this.onlineVideos = onlineVideos;
- }
-
- /**
- * Constructor
- *
- * @param filter Content Filter
- * @param id Container ID
- * @param parentId Parent ID
- */
- public XBoxVideoFoldersContainer(String filter, String id, String parentId) {
- super(filter, id, parentId);
- }
-
- /**
- * Constructor
- *
- * @param filter Content Filter
- * @param id Container ID
- * @param parentId Parent ID
- * @param onlineVideos Online Video Providers
- */
- public XBoxVideoFoldersContainer(String filter, String id, String parentId, List<OnlineVideoProviderService> onlineVideos) {
- super(filter, id, parentId);
- this.onlineVideos = onlineVideos;
- }
-
- @Override
- public void loadContents(long startIndex, long maxCount, SortCriterion[] orderBy, ContentManager contentManager) {
- // Movie
- addContainer(new MovieBaseStorageFolderContainer(filter));
- // Add Online Videos
- if (onlineVideos != null && onlineVideos.size() > 0) {
- for (OnlineVideoProviderService onlineVideo : onlineVideos) {
- VisualContainer onlineVideoContainer = onlineVideo.getRootContainer(filter);
- // Change Online Video Container's Parent ID
- onlineVideoContainer.setParentID(getId());
- addContainer(onlineVideoContainer);
- }
- setChildCount(1 + onlineVideos.size());
- setTotalChildCount(1 + onlineVideos.size());
- } else {
- setChildCount(1);
- setTotalChildCount(1);
- }
- }
-}
View
28 mediaserver.core/src/main/java/org/chii2/mediaserver/upnp/ContentDirectory.java
@@ -5,7 +5,7 @@
import org.chii2.mediaserver.api.content.ContentManager;
import org.chii2.mediaserver.api.content.container.VisualContainer;
import org.chii2.mediaserver.api.http.HttpServerService;
-import org.chii2.mediaserver.api.provider.OnlineVideoProviderService;
+import org.chii2.mediaserver.api.upnp.Filter;
import org.chii2.mediaserver.api.upnp.SearchCriterion;
import org.chii2.mediaserver.content.common.CommonContentManager;
import org.chii2.mediaserver.content.wmp.WMPContentManager;
@@ -36,8 +36,6 @@
private HttpServerService httpServer;
// Transcoder
private TranscoderService transcoder;
- // Online Videos
- private List<OnlineVideoProviderService> onlineVideos;
// Content Manger List
private LinkedList<ContentManager> contentManagers;
// Logger
@@ -49,25 +47,25 @@
* @param mediaLibrary Media Library
* @param httpServer Http Server
* @param transcoder Transcoder
- * @param onlineVideos Online Video Providers
*/
- public ContentDirectory(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder, List<OnlineVideoProviderService> onlineVideos) {
+ public ContentDirectory(MediaLibraryService mediaLibrary, HttpServerService httpServer, TranscoderService transcoder) {
super();
this.mediaLibrary = mediaLibrary;
this.httpServer = httpServer;
this.transcoder = transcoder;
- this.onlineVideos = onlineVideos;
this.contentManagers = new LinkedList<ContentManager>();
- contentManagers.add(new XBoxContentManager(this.mediaLibrary, this.httpServer, this.transcoder, this.onlineVideos));
- contentManagers.add(new WMPContentManager(this.mediaLibrary, this.httpServer, this.transcoder, this.onlineVideos));
- contentManagers.add(new CommonContentManager(this.mediaLibrary, this.httpServer, this.transcoder, this.onlineVideos));
+ contentManagers.add(new XBoxContentManager(this.mediaLibrary, this.httpServer, this.transcoder));
+ contentManagers.add(new WMPContentManager(this.mediaLibrary, this.httpServer, this.transcoder));
+ contentManagers.add(new CommonContentManager(this.mediaLibrary, this.httpServer, this.transcoder));
}
@Override
- public BrowseResult browse(String objectID, BrowseFlag browseFlag, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) throws ContentDirectoryException {
- logger.debug(String.format("ContentDirectory receive browse request with ObjectID:%s, BrowseFlag:%s, Filter:%s, FirstResult:%s, MaxResults:%s, SortCriterion:%s.", objectID, browseFlag, filter, startIndex, requestCount, getSortCriterionString(orderBy)));
+ public BrowseResult browse(String objectID, BrowseFlag browseFlag, String filterString, long startIndex, long requestCount, SortCriterion[] orderBy) throws ContentDirectoryException {
+ logger.debug(String.format("ContentDirectory receive browse request with ObjectID:%s, BrowseFlag:%s, Filter:%s, FirstResult:%s, MaxResults:%s, SortCriterion:%s.", objectID, browseFlag, filterString, startIndex, requestCount, getSortCriterionString(orderBy)));
// Client Headers
UpnpHeaders headers = ReceivingAction.getRequestMessage().getHeaders();
+ // Filter
+ Filter filter = new Filter(filterString);
// Content Manager based on client
ContentManager contentManager = getContentManager(headers);
// DIDL Parser
@@ -136,10 +134,12 @@ else if (browseFlag.equals(BrowseFlag.DIRECT_CHILDREN)) {
}
@Override
- public BrowseResult search(String containerId, String searchCriteria, String filter, long startIndex, long requestCount, SortCriterion[] orderBy) throws ContentDirectoryException {
- logger.debug(String.format("ContentDirectory receive search request with ContainerID:%s, SearchCriteria:%s, Filter:%s, FirstResult:%s, MaxResults:%s, SortCriterion:%s.", containerId, searchCriteria, filter, startIndex, requestCount, getSortCriterionString(orderBy)));
+ public BrowseResult search(String containerId, String searchCriteria, String filterString, long startIndex, long requestCount, SortCriterion[] orderBy) throws ContentDirectoryException {
+ logger.debug(String.format("ContentDirectory receive search request with ContainerID:%s, SearchCriteria:%s, Filter:%s, FirstResult:%s, MaxResults:%s, SortCriterion:%s.", containerId, searchCriteria, filterString, startIndex, requestCount, getSortCriterionString(orderBy)));
// Client Headers
UpnpHeaders headers = ReceivingAction.getRequestMessage().getHeaders();
+ // Filter
+ Filter filter = new Filter(filterString);
// Content Manager based on client
ContentManager contentManager = getContentManager(headers);
// Search Criterion
@@ -207,6 +207,6 @@ protected ContentManager getContentManager(UpnpHeaders headers) {
return contentManager;
}
}
- return new CommonContentManager(this.mediaLibrary, this.httpServer, this.transcoder, this.onlineVideos);
+ return new CommonContentManager(this.mediaLibrary, this.httpServer, this.transcoder);
}
}
View
22 mediaserver.core/src/main/java/org/chii2/mediaserver/upnp/MediaServerServiceImpl.java
@@ -3,7 +3,6 @@
import org.apache.commons.lang.StringUtils;
import org.chii2.medialibrary.api.core.MediaLibraryService;
import org.chii2.mediaserver.api.http.HttpServerService;
-import org.chii2.mediaserver.api.provider.OnlineVideoProviderService;
import org.chii2.mediaserver.api.upnp.MediaServerService;
import org.chii2.transcoder.api.core.TranscoderService;
import org.slf4j.Logger;
@@ -47,8 +46,6 @@
private HttpServerService httpService;
// Transcoder
private TranscoderService transcoder;
- // Online Videos
- private List<OnlineVideoProviderService> onlineVideos;
// Logger
private Logger logger = LoggerFactory.getLogger("org.chii2.mediaserver.upnp");
@@ -116,7 +113,7 @@ public LocalDevice createUPnPDevice()
// Windows Media Player Device Details
DeviceDetails wmpDetails = new DeviceDetails(
- "Chii2 : " + serverPrefix,
+ serverPrefix + ": Chii2",
new ManufacturerDetails("Chii2", "http://www.chii2.org/"),
new ModelDetails("Windows Media Player Sharing", "Windows Media Player Sharing", "12.0"),
"000da201238c",
@@ -130,8 +127,9 @@ public LocalDevice createUPnPDevice()
})
);
+ // Common Details
DeviceDetails chii2Details = new DeviceDetails(
- "Chii2",
+ serverPrefix + ": Chii2",
new ManufacturerDetails("Chii2", "http://www.chii2.org/"),
new ModelDetails("Chii2 Home Server", "Chii2 Home Server", "1"),
"000da201238c",
@@ -147,7 +145,7 @@ public LocalDevice createUPnPDevice()
// Device Details Provider
Map<HeaderDeviceDetailsProvider.Key, DeviceDetails> headerDetails = new HashMap<HeaderDeviceDetailsProvider.Key, DeviceDetails>();
- //headerDetails.put(new HeaderDeviceDetailsProvider.Key("User-Agent", "FDSSDP"), wmpDetails);
+ headerDetails.put(new HeaderDeviceDetailsProvider.Key("User-Agent", "FDSSDP"), wmpDetails);
headerDetails.put(new HeaderDeviceDetailsProvider.Key("User-Agent", "Xbox.*"), wmpDetails);
headerDetails.put(new HeaderDeviceDetailsProvider.Key("X-AV-Client-Info", ".*PLAYSTATION 3.*"), chii2Details);
HeaderDeviceDetailsProvider provider = new HeaderDeviceDetailsProvider(chii2Details, headerDetails);
@@ -160,7 +158,7 @@ public LocalDevice createUPnPDevice()
new DefaultServiceManager<ContentDirectory>(contentDirectory, null) {
@Override
protected ContentDirectory createServiceInstance() throws Exception {
- return new ContentDirectory(mediaLibrary, httpService, transcoder, onlineVideos);
+ return new ContentDirectory(mediaLibrary, httpService, transcoder);
}
}
);
@@ -322,14 +320,4 @@ public void setHttpService(HttpServerService httpService) {
public void setTranscoder(TranscoderService transcoder) {
this.transcoder = transcoder;
}
-
- /**
- * Inject Online Video Providers
- *
- * @param onlineVideos Online Video Providers
- */
- @SuppressWarnings("unused")
- public void setOnlineVideos(List<OnlineVideoProviderService> onlineVideos) {
- this.onlineVideos = onlineVideos;
- }
}
View
6 mediaserver.core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -14,19 +14,13 @@
<reference id="transcoderService" interface="org.chii2.transcoder.api.core.TranscoderService">
</reference>
- <!-- Online Video Provider Service List -->
- <reference-list id="onlineVideoProviders" interface="org.chii2.mediaserver.api.provider.OnlineVideoProviderService"
- availability="optional">
- </reference-list>
-
<!-- Chii2 Media Server Core Bean -->
<bean id="mediaServerService" class="org.chii2.mediaserver.upnp.MediaServerServiceImpl"
init-method="init"
destroy-method="destroy">
<property name="mediaLibrary" ref="mediaLibraryManager"/>
<property name="httpService" ref="httpServerService"/>
<property name="transcoder" ref="transcoderService"/>
- <property name="onlineVideos" ref="onlineVideoProviders"/>
</bean>
<!-- Chii2 Media Server Core Service -->
View
2 mediaserver.core/src/test/java/org/chii2/mediaserver/content/ContentManagerTest.java
@@ -15,7 +15,7 @@
* Constructor
*/
public ContentManagerTest() {
- contentManger = new CommonContentManager(null, null, null, null);
+ contentManger = new CommonContentManager(null, null, null);
}
@Test
View
5 mediaserver.http/src/main/java/org/chii2/mediaserver/http/HttpServerServiceImpl.java
@@ -144,11 +144,6 @@ public URI forgeUrl(String mediaType, String clientProfile, boolean transcoded,
return HttpUrl.forgeURL(getHost().getHostAddress(), getPort(), mediaType, clientProfile, transcoded, mediaId);
}
- @Override
- public URI forgeUrl(String mediaType, String provider, String clientProfile, boolean transcoded, String url) {
- return HttpUrl.forgeURL(getHost().getHostAddress(), getPort(), mediaType, provider, clientProfile, transcoded, url);
- }
-
/**
* Get host IP address
*
View
43 mediaserver.http/src/main/java/org/chii2/mediaserver/http/bio/HttpHandler.java
@@ -1,10 +1,8 @@
package org.chii2.mediaserver.http.bio;
import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.http.*;
import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.FileEntity;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.util.EntityUtils;
@@ -14,6 +12,8 @@
import org.chii2.medialibrary.api.persistence.entity.MovieFile;
import org.chii2.mediaserver.api.dlna.DLNATransport;
import org.chii2.mediaserver.api.http.HttpUrl;
+import org.chii2.mediaserver.http.bio.entity.ImageEntity;
+import org.chii2.transcoder.api.core.ImageTranscoderProcess;
import org.chii2.transcoder.api.core.TranscoderProcess;
import org.chii2.transcoder.api.core.TranscoderService;
import org.slf4j.Logger;
@@ -78,33 +78,29 @@ public void handle(
logger.debug("Chii2 Media Server Http Server requested url parse error.");
} else {
String type = map.get("type");
- String provider = map.get("provider");
String clientProfile = map.get("client");
boolean transcoded = BooleanUtils.toBoolean(map.get("transcoded"), "1", "0");
String id = map.get("id");
- String url = map.get("url");
// Query the library and get the entity
HttpEntity entity = null;
if ("image".equalsIgnoreCase(type)) {
// Image
Image image = this.mediaLibrary.getImageById(id);
if (image != null) {
+ // Image File
+ File imageFile = new File(image.getAbsolutePath());
+ // MIME
+ String mime = this.transcoder.getImageTranscodedMime(clientProfile, image.getType(), image.getWidth(), image.getHeight());
+ // Transcoding
if (!transcoded) {
- // Image File
- List<File> files = new ArrayList<File>();
- File imageFile = new File(image.getAbsolutePath());
- files.add(imageFile);
- // MIME
- String mime = this.transcoder.getImageTranscodedMime(clientProfile, image.getType(), image.getWidth(), image.getHeight());
- // HTTP Entity
- entity = new RangeFileEntity(files, mime, range);
- if (range != null) {
- response.setStatusCode(HttpStatus.SC_PARTIAL_CONTENT);
- } else {
- response.setStatusCode(HttpStatus.SC_OK);
- }
+ entity = new ImageEntity(imageFile, mime);
+ } else {
+ ImageTranscoderProcess process = this.transcoder.getImageTranscodedProcess(clientProfile, imageFile, image.getType(), image.getWidth(), image.getHeight());
+ entity = new ImageEntity(process, mime);
}
+ // Response
+ response.setStatusCode(HttpStatus.SC_OK);
}
} else if ("movie".equalsIgnoreCase(type)) {
Movie movie = mediaLibrary.getMovieById(id);
@@ -136,19 +132,6 @@ public void handle(
entity = new ByteArrayEntity(thumb);
response.setStatusCode(HttpStatus.SC_OK);
}
- } else if ("onlinevideo".equalsIgnoreCase(type)) {
- String mime = transcoder.getOnlineVideoTranscodedMime(provider, clientProfile, url);
- if (StringUtils.isBlank(mime)) {
- logger.error("Can't determine Online Video {} for client {} 's MIME, this could result a error.", url, clientProfile);
- }
- List<TranscoderProcess> processes = transcoder.getOnlineVideoTranscodedProcesses(provider, clientProfile, url);
- entity = new RangeTranscodedEntity(processes, mime, range);
- if (range != null) {
- response.setStatusCode(HttpStatus.SC_PARTIAL_CONTENT);
- } else {
- response.setStatusCode(HttpStatus.SC_OK);
- }
-
}
if (entity == null) {
View
108 mediaserver.http/src/main/java/org/chii2/mediaserver/http/bio/entity/ImageEntity.java
@@ -0,0 +1,108 @@
+package org.chii2.mediaserver.http.bio.entity;
+
+import org.apache.http.entity.AbstractHttpEntity;
+import org.chii2.transcoder.api.core.ImageTranscoderProcess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+
+/**
+ * Image HTTP Entity
+ */
+public class ImageEntity extends AbstractHttpEntity implements Cloneable {
+ // Buffer Size
+ private final static int BUFFER_SIZE = 4096;
+ // Image File
+ private File imageFile;
+ // Transcoder Process
+ private ImageTranscoderProcess process;
+ // Logger
+ private Logger logger = LoggerFactory.getLogger("org.chii2.mediaserver.http");
+
+ /**
+ * Constructor
+ *
+ * @param imageFile Image File
+ * @param contentType Content Type
+ */
+ public ImageEntity(File imageFile, String contentType) {
+ this.imageFile = imageFile;
+ // Content Type
+ setContentType(contentType);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param process Image Transcoder Process
+ * @param contentType Content Type
+ */
+ public ImageEntity(ImageTranscoderProcess process, String contentType) {
+ this.process = process;
+ // Content Type
+ setContentType(contentType);
+ }
+
+ @Override
+ public boolean isRepeatable() {
+ return this.process == null;
+ }
+
+ @Override
+ public long getContentLength() {
+ logger.info("Request for content length");
+ if (this.imageFile != null && this.imageFile.exists() && this.imageFile.isFile()) {
+ return this.imageFile.length();
+ } else {
+ return -1;
+ }
+ }
+
+ @Override
+ public InputStream getContent() throws IOException, IllegalStateException {
+ if (this.imageFile != null && this.imageFile.exists() && this.imageFile.isFile()) {
+ return new FileInputStream(this.imageFile);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void writeTo(OutputStream outputStream) throws IOException {
+ if (outputStream == null) {
+ throw new IllegalArgumentException("Output stream may not be null");
+ }
+
+ byte[] buffer = new byte[BUFFER_SIZE];
+ InputStream inputStream = null;
+ try {
+ // Transcoding
+ if (this.process != null) {
+ this.process.init();
+ this.imageFile = this.process.getOutputFile();
+ }
+
+ if (this.imageFile != null && this.imageFile.exists() && this.imageFile.isFile()) {
+ inputStream = new FileInputStream(this.imageFile);
+ int line;
+ while ((line = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, line);
+ }
+ outputStream.flush();
+ }
+ } finally {
+ if (this.process != null) {
+ this.process.destroy();
+ }
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ }
+
+ @Override
+ public boolean isStreaming() {
+ return false;
+ }
+}
View
68 mediaserver.provider.sohu/pom.xml
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>chii2</artifactId>
- <groupId>org.chii2</groupId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>chii2.mediaserver.provider.sohu</artifactId>
- <packaging>bundle</packaging>
-
- <name>Chii2 Media Server Online Video Provider Sohu</name>
- <url>http://www.chii2.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.chii2</groupId>
- <artifactId>chii2.mediaserver.api</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jsoup</groupId>
- <artifactId>jsoup</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Export-Package>org.chii2.mediaserver.provider.sohu.*</Export-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>