Ejemplo n.º 1
0
        private Task <AtemFrame> GetFrameFromJob(AtemMediaCacheItem image)
        {
            Task <AtemFrame> frameTask = null;

            lock (image.JobLock)
            {
                frameTask = image.RawFrame;
            }

            if (frameTask == null)
            {
                throw new Exception("Download of still not queued...");
            }

            return(frameTask);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetImage(string deviceId, string hash)
        {
            // TODO - quality/format selector

            var client = _repo.GetConnection(deviceId);

            if (client == null)
            {
                return(BadRequest("Device not found"));
            }

            AtemMediaCacheItem image = client.GetImage(hash.ToUpper());

            if (image == null)
            {
                return(NotFound());
            }

            if (image.PreviewJpeg == null)
            {
                AtemFrame frame = await GetFrameFromJob(image);

                // TODO - this makes a lot of assumptions about color space and resolution
                using Image image2 = Image.LoadPixelData <Rgba32>(frame.GetRGBA(ColourSpace.BT709), 1920, 1080);

                // TODO - is this a good resolution?
                image2.Mutate(x => x.Resize(640, 0));

                var outStream = new MemoryStream();
                await image2.SaveAsJpegAsync(outStream);

                image.PreviewJpeg = outStream.ToArray();
            }

            return(File(image.PreviewJpeg, "image/jpeg"));
        }