aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/HttpHandlers/VideoHandler.cs
blob: f94b8fc3117aa25657b799990544fa883e8e047b (plain)
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;

namespace MediaBrowser.Api.HttpHandlers
{
    class VideoHandler : BaseMediaHandler<Video>
    {
        public IEnumerable<string> VideoFormats
        {
            get
            {
                return QueryString["videoformats"].Split(',');
            }
        }

        /// <summary>
        /// Gets the format we'll be converting to
        /// </summary>
        protected override string GetOutputFormat()
        {
            return VideoFormats.First();
        }

        protected override bool RequiresConversion()
        {
            // If it's not in a format the consumer accepts, return true
            if (!VideoFormats.Any(f => LibraryItem.Path.EndsWith(f, StringComparison.OrdinalIgnoreCase)))
            {
                return true;
            }
            
            AudioStream audio = LibraryItem.AudioStreams.FirstOrDefault();

            if (audio != null)
            {
                // If the number of channels is greater than our desired channels, we need to transcode
                if (AudioChannels.HasValue && AudioChannels.Value < audio.Channels)
                {
                    return true;
                }
            }

            // Yay
            return false;
        }

        protected override Task WriteResponseToOutputStream(Stream stream)
        {
            throw new NotImplementedException();
        }
    }
}